[R] keeping all rows with the same values, and not only unique ones

Dimitri Liakhovitski ld7631 at gmail.com
Fri Sep 25 00:52:00 CEST 2009


Dear R-ers,

I have a data frame "test":
test<-data.frame(x=c(1,2,3,4,5,6,7,8),y=c(2,3,4,5,6,7,8,9),total=c(7,7,8,8,9,9,10,10))
test

I have a vector "needed":
needed<-c(7,9)
needed

I need the result to look like this:
1 2 7
2 3 7
5 6 9
6 7 9

When I do the following:
result<-test[test["total"]==needed,]
result

I only get unique rows that have 7 or 9 in "total":
1 2 7
6 7 9

How could I keep ALL rows that have 7 or 9 in "total"

Thanks a million!

-- 
Dimitri Liakhovitski
Ninah.com
Dimitri.Liakhovitski at ninah.com




More information about the R-help mailing list