How do I categorize my data for a datamining procedure?

给你一囗甜甜゛ 提交于 2020-01-13 11:49:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!