I am trying to create a decision tree using rpart using a data frame that has ~ 200 columns. Some of these columns have numbers in their names, some have special characters (for example, "/"). When I try to generate a tree, I get an error, for example, the following:
R> gg.rpart <- rpart(nospecialchar ~ Special/char, data=temp, method="class") Error in eval(expr, envir, enclos) : object 'Special' not found R> gg.rpart <- rpart(nospecialchar ~ "Special/char", data=temp, method="class") Error in terms.formula(formula, data = data) : invalid model formula in ExtractVars R> gg.rpart <- rpart(nospecialchar ~ `Special/char`, data=temp, method="class") Error in `[.data.frame`(frame, predictors) : undefined columns selected
Do I need to change names to accommodate R, or is there a way to pass column names with special characters in R formulas?
source share