On May 17, 2013, at 12:02 , peter dalgaard wrote: > > On May 17, 2013, at 08:51 , Sparks, John James wrote: > >> Dear R Helpers, >> >> I need help with a slightly unusual situation in which I am trying to >> select some columns from a data frame. I know how to use the subset >> statement with column names as in: > > Notice that subset() is a convenience function for command line use. The > non-standard evaluation tricks in it tend to become inconveniences if you try > to use subset() in a function (I can say that, I wrote the blasted thing...). > Just use normal subseting functions instead and everything behaves much more > predictably. If ImportantVars is a vector of column names, use > > mtcars[ImportantVars] > > (or mtcars[,ImportantVars], which also works for matrices). >
Oups, Pascal has the right end of the stick. The above is correct, but the "If" is important: You need a character vector of names, and that's not what is in ImportantVars. -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd....@cbs.dk Priv: pda...@gmail.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.