Re: [R] help with subset

From: Christos Hatzis <christos.hatzis_at_nuverabio.com>
Date: Sat, 03 May 2008 00:01:58 -0400

Try %in%

subset(dat, treatment %in% vec)

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of
> partofy_at_inoutbox.com
> Sent: Friday, May 02, 2008 11:41 PM
> To: r-help_at_r-project.org
> Subject: [R] help with subset
>
> 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
>
> --
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 03 May 2008 - 03:59:45 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 03 May 2008 - 04:30:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive