[R] subsetting by cell value with a list
gsee000 at gmail.com
Thu Mar 15 21:38:22 CET 2012
> my.df <- data.frame(IDX=1:42, x=rnorm(1:42))
> my.df[my.df$IDX %in% c(17, 42), ]
17 17 -0.5110095
42 42 -1.0686427
On Thu, Mar 15, 2012 at 3:25 PM, Ed Siefker <ebs15242 at gmail.com> wrote:
> I would like to subset by dataframe by matching all rows that have any value
> from a list of values. I can get it to work if I have exactly one value,
> I'm not
> sure how to do it with a list of values though.
> This works and gives me exactly one line:
> my.df[ which( mydf$IDX==17)), ]
> I would like to do something like this:
> my.df[ which( mydf$IDX==c(17, 42), ]
> Obviously that won't work, but I hope the meaning is clear.
> What's the right way to express this?
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help