[R] help with subset

partofy at inoutbox.com partofy at inoutbox.com
Sat May 3 05:40:50 CEST 2008


Dear list:

I have a problem using the subset function:

dat<- data.frame(treatment=c("A", "B", "A", "C", "C", "D", "A", "D",
"C", "D"), response=rnorm(10))

I am interested in treatments "A", "B" and "D"
vec<- c("A", "B", "D")

But I can only obtain what I want with:
subset(dat, treatment=="A" | treatment=="B" | treatment=="D")

What's wrong with
subset(dat, treatment==vec)

It would be much more simple to compute the latter in a rather complex
dataframe.
Thanks in advance
Justin
-- 
  
  partofy at inoutbox.com

--



More information about the R-help mailing list