Joel Fürstenberg-Hägg
2009-Nov-24 13:50 UTC
[R] Decision trees with factors and numericals
Hi all, Does any of you know how to make a decision tree when the data set contains factors and numericals? I've got a data frame with 3 columns, where y and x1 are numerical and x2 contains factors. Is it possible to use the rpart package, and in that case how? Otherwise, is there another alternative? This is what I've tried so far> rpart(LT50_NA ~ Raf + Antho, data=decTreeNA, method=anova) # Have tried "method=class" as wellError in as.character(x) : cannot coerce type 'closure' to vector of type 'character' Best regards, Joel _________________________________________________________________ Lagra alla dina foton på Skydrive. Det är enkelt och säkert! http://www.skydrive.live.com [[alternative HTML version deleted]]
On Nov 24, 2009, at 8:50 AM, Joel F?rstenberg-H?gg wrote:> > Does any of you know how to make a decision tree when the data set > contains factors and numericals? > > I've got a data frame with 3 columns, where y and x1 are numerical > and x2 contains factors. Is it possible to use the rpart package, > and in that case how? Otherwise, is there another alternative? > > This is what I've tried so far > >> rpart(LT50_NA ~ Raf + Antho, data=decTreeNA, method=anova) # Have >> tried "method=class" as well > Error in as.character(x) : > cannot coerce type 'closure' to vector of type 'character' >I do not think that error is arising because you have a factor on the RHS of the equation. It would have been extremely surprising to find that rpart would be complaining about encountering a factor. I think it is because you failed to enclose anova with quotes. The message is telling you that R encountered a function (a closure) where it was "hoping for" a character variable.>-- David Winsemius, MD Heritage Laboratories West Hartford, CT