I am sure this question has come up, but searching hasn't given me any results.
So I need to enter this line: mx1 <- randomForest(X1 ~ elevation + slope + vegtype, data = moths.train) But the problem is that X1 is currently hard coded. I would instead like to be able to put in the value of X1 through a list. For example: list <- list("X1", "X2", "X3") #Then, instead of X1, I want to put list[1] mx1 <- randomForest(list[1] ~ elevation + slope + vegtype, data = moths.train) randomForest does not accept list[1] as a valid entry, so how can I get it to accept it as X1, instead of list[1]? Thanks -- View this message in context: http://www.nabble.com/Using-a-variable-in-the-formula-tp26071598p26071598.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.