Re: [R] subset dataset using factor levels instead of factor names

From: Phil Spector <spector_at_stat.berkeley.edu>
Date: Tue, 22 Jun 2010 16:43:22 -0700 (PDT)

Rachel -

    Not exactly a reproducible example, but maybe

t1 <- subset(nih2009, ic_name %in% levels(nih2009$ic_name)[c(27,51)])

On Tue, 22 Jun 2010, Hayes, Rachel M wrote:

> Hi All,
>
> I have a factor variable with 52 levels -with long, annoying names. I want to keep only rows with some variables. I can do this using this code:
>
> test1 <- subset(nih2009,ic_name %in% c('NATIONAL EYE INSTITUTE','Veterans Affairs'))
> dim(test1)
>
> [1] 2396 38
>
> But this doesn't work:
>
> t1 <- subset(nih2009, ic_name %in% c(27,51))
> dim(t1)
> [1] 0 38
>
>
> I know there's a way to do this. Any help? Thanks,
>
> Rachel
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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 Tue 22 Jun 2010 - 23:45:40 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 Wed 23 Jun 2010 - 00:00:34 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