Skip to content
Prev 209754 / 398500 Next

Access variables by string

Philipp Rappold wrote:
Well, you can use get(varname)[2] or more generally things like
eval(bquote(.(as.name(varname))[2])), but for this particular
application, why not just use the standard indexing techniques?

I think this will do

ix <- apply(is.na(data[varnames]), 1, any)
data[!ix,]

e.g.
FALSE  TRUE
  116    37
Ozone Solar.R    Wind    Temp   Month     Day
     37       7       0       0       0       0
FALSE  TRUE
  111    42


(Using functions like subset inside another function often leads to
problems because of the nonstandard evaluation tricks that it uses. It
is mainly useful to save tying on the command line.)