Search code examples
rassociationsrulesaprioriarules

R: apriori error about not able to coerce NA's to nsparseMatrix


I am experimenting with the apriori algorithm in the arules package.

This is what I've done: I loaded a view from SQL Server into R. Since that data is not in transactions form (to use in apriori), I had to convert it:

data <- sapply(orders, as.factor)

Then I entered the apriori function:

apriori(data, parameter = list (support=0.005, confidence=0.5))

I get this error:

Error in t(as(from, "ngCMatrix")) : error in evaluating the argument 'x' in selecting a method for function 't': Error in asMethod(object) : cannot coerce 'NA's to "nsparseMatrix"

I checked with a query and I don't even have any attribute that is NULL/NA.

I don't understand what the error means. Does someone know what the problem is and how to solve this?


Solution

  • I have encountered the same kind of error recently. All I have learnt was that your data have to be coerced to transactions for mining the itemsets or rules. This piece of code should be helpful.

    transaction_data<- as(data, "transactions")
    rules <- apriori(transaction_data,parameter = list(minlen=2,supp=0.2,conf=0.5))