Solved – arules R – How to ignore unknown item label in appearance list

I am mining for association rules using arules. I often run new transaction sets with the same code. I dont change the list of restrictions on which items may appear in the rhs and lhs, but sometimes the transaction set does not have an item that is in my rhs or lhs list.

Is there any way to make R ignore this?

> library('arules'); > txn = read.transactions(file="Query1.csv",rm.duplicates=FALSE,format="single",sep=",",cols=c(1,2)); > llist <-scan('gpis.txt', what="", sep="n"); Read 5505 items > rlist <-scan('hccs.txt', what="", sep="n"); Read 127 items > rules <- apriori(txn, parameter = list(confidence = 0.5), appearance = list(rhs = rlist, lhs = llist)); Error in asMethod(object) :    "blah" is an unknown item label, "blab" is an unknown item label.....  

I am not familiar with association rules and cannot reproduce your results (you can use dput(sample_data) to generate code that will recreate your data) but your problem looks like missing factor levels when comparing one data ensemble to another. You can drop and reset levels using droplevels and levels to make sure your data sets have the same number of factors. Here is an example:

Z = as.factor(sample(LETTERS[1:5],20,replace=T)) levels(Z) Y = as.factor(Z[-which(Z %in% LETTERS[4:5])]) levels(Y) Y=droplevels(Y) # drop the levels that are not used levels(Y) levels(Y) = levels(Z) # bring them back levels(Y) Y = factor(Y,levels=LETTERS[1:7]) # expand the levels levels(Y) 

Similar Posts:

Rate this post

Leave a Comment