问题
I am doing a data mining procedure, using the apriori
function. This function only works on categorical data, without values but only text. My dataset fulfills these requirements, as I have five categorial variables, without numerical values but only text (so the variable 'sex' is categorized into 'female' and 'male')
If I now try the apriori()
function, I get the following error:
apriori(data)
Error in asMethod(object)
:
column(s) 1, 2, 3, 4, 5 not logical or a factor. Use as.factor or categorize first.
Although my data looks categorical, R does not get that it is. How do I use for instance the as.factor function to categorize my data properly, so that the apriori function works?
回答1:
You can convert all your columns to a factor:
data <- sapply(data,as.factor)
回答2:
For me
data <- data.frame(sapply(data,as.factor))
rules<- apriori(data)
Works well
来源:https://stackoverflow.com/questions/20161530/how-do-i-categorize-my-data-for-a-datamining-procedure