[R] subsetting a dataframe
yjmha69
yjmha69 at yahoo.com
Fri Jun 4 21:28:22 CEST 2010
Hi there,
> a<-data.frame(c(1,2,2,5,9,9),c("A","B","C","D","E","F"))
> names(a)<-c("x1","x2")
> max(table(a$x1))
[1] 2
>
The above shows the max count for x1 is 2, which is correct. But we can't tell
there are 2 groups that meet this criteria: 2,2 and 9,9.
I then want to extract the records that has the hightest count
> a[max(table(a$x1)),]
x1 x2
2 2 B
This is not working, since it is equvalent to a[2,]
What I want is
x1 x2
2 2 B
3 2 C
5 9 E
5 9 F
I think this should be very easy, but I'm a beginner :-)
Thanks
YJM
More information about the R-help
mailing list