discretize function of multiple columns

Antonio López Ruiz picture Antonio López Ruiz · Aug 3, 2016 · Viewed 7.1k times · Source

I have the following csv: https://github.com/antonio1695/Python/blob/master/nearBPO/facturasprueba.csv

With it I want to use the apriori function to find association rules. However, I get the error:

Error in asMethod(object) : column(s) 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 not logical or a factor. Discretize the columns first.

I have already bumped into this error before, and what I did was:

dataframe$columnX <- discretize(df$columnX) 

However, this only works if I select manually each column and discretize them one by one. I would like to do the same thing but for aprox 3k columns. The case I gave you has only 11, I'm guessing that 11 will do.

Answer

Antonio L&#243;pez Ruiz picture Antonio López Ruiz · Aug 3, 2016

I found the answer, thanks for everyones help though. To select and discretize multiple columns:

for (i in 2:12){df[,i]<-discretize(df[,i])}