0

I apologize if this has already been asked before, but I can't even think of a great way to describe the issue I have. Basically, I have a dataframe that has 30 columns in it. I want to use randomForest on it to predict one of the columns, but I also don't want to manually type each of the remaining 29 columns. Is there a better way to do this?

David Arenburg
  • 91,361
  • 17
  • 137
  • 196
Ram
  • 290
  • 1
  • 5
  • 14
  • 6
    `y~.`. This is definitely a duplicate. – Ari B. Friedman Feb 14 '15 at 18:36
  • Could you link to that thread, Ari? – Ram Feb 14 '15 at 19:01
  • I get the following error for apply: "Error in if (n == 0) stop("data (x) has 0 rows") : argument is of length zero" Any suggestions as to why? Also, doesn't your method lack the ability to specify which column you're trying to predict? Remember randomForest looks like randomForest(col1 ~ col2 + col3 + col4, data=train)? I'm new to R, sorry if I'm asking basic questions. – Ram Feb 14 '15 at 19:04
  • Do you have a link to the data or paste up an example? – J. Win. Feb 14 '15 at 19:08
  • I'm using the Forest Cover data from Kaggle. https://www.kaggle.com/c/forest-cover-type-prediction/data - I'm just trying to get a feel for the data, really. I want to see how randomForest predicts things. – Ram Feb 14 '15 at 19:10
  • Have you tried: `randomForest( col1 ~ . , data=train)`? – IRTFM Feb 14 '15 at 19:31
  • Oh, that worked perfect, BondedDust. Thanks so much! This will save me quite a bit of time in the future. – Ram Feb 14 '15 at 20:32

0 Answers0