Skip to content
Prev 69509 / 398525 Next

Subset with selection variable from function argument. Is there another way?

Fredrik Karlsson wrote:

            
The line above is
  a) syntactically incorrect and
  b) the string does not describe a variable in the mammals data
hence this is not reproducible at all.
Let's assume
   set <- "body"

Either use get() as in
   subset(mammals, get(set) > 2)
or simple indexing such as:
   subset(mammals, mammals[[set]] > 2)


Uwe Ligges