Re: [R] subsetting by cell value with a list

2012-03-15 Thread David Winsemius
On Mar 15, 2012, at 4:38 PM, G See wrote: my.df <- data.frame(IDX=1:42, x=rnorm(1:42)) my.df[my.df$IDX %in% c(17, 42), ] IDX x 17 17 -0.5110095 42 42 -1.0686427 subset(my.df, IDX %in% c(17,42) ) (I find subset to give clearer code than: df[which(df$colname cond>) , ], plus it c

Re: [R] subsetting by cell value with a list

2012-03-15 Thread Petr Savicky
On Thu, Mar 15, 2012 at 03:47:24PM -0500, G See wrote: > On second thought, I must not understand your question because your > code works fine for me. > > > my.df[ which(my.df$IDX == c(17, 42)), ] >IDX x > 17 17 -0.5110095 > 42 42 -1.0686427 Hi. This seems to work due to the fact

Re: [R] subsetting by cell value with a list

2012-03-15 Thread G See
On second thought, I must not understand your question because your code works fine for me. > my.df[ which(my.df$IDX == c(17, 42)), ] IDX x 17 17 -0.5110095 42 42 -1.0686427 > my.df[my.df$IDX == c(17, 42), ] IDX x 17 17 -0.5110095 42 42 -1.0686427 Can you provide samp

Re: [R] subsetting by cell value with a list

2012-03-15 Thread G See
> my.df <- data.frame(IDX=1:42, x=rnorm(1:42)) > my.df[my.df$IDX %in% c(17, 42), ] IDX x 17 17 -0.5110095 42 42 -1.0686427 Garrett On Thu, Mar 15, 2012 at 3:25 PM, Ed Siefker wrote: > I would like to subset by dataframe by matching all rows that have any value > from a list of valu

[R] subsetting by cell value with a list

2012-03-15 Thread Ed Siefker
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