Question

I am using Rattle to run randomForest against my training data set. One of the variables has values FALSE and TRUE.

     > str(mydata)
     'data.frame':  421570 obs. of  2 variables:
     $ Trial       : int  1 1 1 1 1 1 1 1 1 1 ...
     $ IsHoliday   : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...

I am able to convert the same to a factor in R.

     > mydata$IsHoliday <- factor(mydata$IsHoliday)
     > str(mydata)
     'data.frame':  421570 obs. of  2 variables:
     $ Trial       : int  1 1 1 1 1 1 1 1 1 1 ...
     $ IsHoliday   : Factor w/ 2 levels "FALSE","TRUE": 1 1 1 1 1 1 1 1 1 1 ...

When I write the data.frame to a CSV and load it using Rattle, again I am seeing it as logical only. Due to this, I am getting the error, Error in na.roughfix.data.frame(x) + na.roughfix only works for numeric or factor

Any help is appreciated. Thanks in advance

Was it helpful?

Solution

I think you should try including "as"

mydata$IsHoliday=as.factor(mydata$IsHoliday)   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top