0

I have Document Term Matrix turned data frame with 352 observations of 1342 variables. Now when I try to run a randomforest model I get the error:

model <- randomForest(labels~ ., data = train_df, ntree = 100)

Error in model.frame.default(terms(reformulate(attributes(Terms)$term.labels)), : invalid type (special) for variable 'repeat'

I know 'repeat' is a reserve word in R, but how can I solve this issue. I cannot even change the column name in this condition and find it difficult to find a solution on net.

Help in this matter will be highly appreciated.

I have tried this but is doesnt help:

model <- randomForest(labels~ ., data = train_df, ntree = 100, `repeat` = train_df$`repeat`)
  • Have you tried converting the words to capitals with `toupper`? – Andrew Gustar Mar 10 '23 at 13:17
  • 3
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. I can't replicate the issue. I get no error with `dd <- data.frame(`repeat`=rnorm(100), labels=runif(100)); randomForest(labels~., data=dd)` – MrFlick Mar 10 '23 at 14:53
  • Somewhere you appear to be converting your text labels into the equivalent of `eval()` . Either that or you named a variable in your current environment the same as a function name, which is bad practice whether the name is "repeat" , "sin" , "c", or any non-reserved function name. – Carl Witthoft Mar 10 '23 at 15:53

0 Answers0