[R] Variable passed to function not used in function in select=... in subset

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Tue Nov 11 09:49:31 CET 2008


Gabor Grothendieck wrote:
>
> Regarding the convenience it occurs in expressions like this:
>
>    iris2 <- subset(iris, select = - Species)
>
> to create a data frame without the Species column.
>   

aha!  so what's you best guess about the result here:

d = data.frame(a = 1)
d$`-b` = 2
names(d)
# here we go

subset(d, select = -b)
# to b or not to b?

b = "a"
subset(d, select = -b)
# tragedy

d$b = 3
subset(d, select = -b)
# catharsis

(for whatever reason a user may choose to have a column named '-b')


vQ



More information about the R-help mailing list