Skip to content
Prev 284822 / 398502 Next

subset select="variable with a list of names"

On Feb 9, 2012, at 18:17 , Nordlund, Dan (DSHS/RDA) wrote:

            
Well, I'll bite. Using subset() inside functions is usually asking for trouble. 

It's much easier just to use the basic indexing features:

mydata[ , c("age","day"), drop=FALSE]

You can encapsulate that in a function, if you like (not that it really buys you much)

x <- function(names) mydata[, names, drop=FALSE]

(you may or may not want the drop=FALSE, see help(Extract))