[R] subset using noncontiguous variables by name (not index)
pinard at iro.umontreal.ca
Sun Aug 26 23:30:28 CEST 2007
[Muenchen, Robert A (Bob)]
>I'm using the subset function to select a list of variables, some of
>which are contiguous in the data frame, and others of which are not. It
>works fine when I use the form:
>In reality, my list is far more complex. So I would like to store it in
>a variable to substitute in for c(x1,x3:x5,x7) but cannot get it to
>work. That use of the c function seems to violate R rules, so I'm not
>sure how it works at all. A small simulation of the problem is below.
>mydata <- data.frame(
># This does what I want.
>summary(subset(mydata, select=c(x1, x3:x5, x7)))
variables <- expression(c(x1, x3:x5, x7))
However, I do not know how one computes the expression piecemeal, that
is, better than by building a string and parsing the result.
François Pinard http://pinard.progiciels-bpi.ca
More information about the R-help