[R] subsetting matrix according to columns with character index
Ralph S.
ruffel1 at hotmail.com
Wed Aug 13 20:00:27 CEST 2008
Hi,
I have a long matrix of the following form which I would like to subset according to the third column:
[x y z]:
a1 c1 1
a1 c1 2
a2 c1 1
a1 c2 1
a1 c2 2
. . .
The first two columns a characters ai and cj.
I would like to keep all the rows where there are two entries for z, 1 and 2.
That is, I want:
a1 c1 1
a1 c1 2
a1 c2 1
a1 c2 2
. . .
I try to use something like df[by(df,c(df$x,df$y),sum(z)==3),] but that only gives me one line of data per x y combination.
Is there an easy way of coding to keep all rows for a and c combinations where z has entries both 1 and 2?
Many thanks,
Ralph
_________________________________________________________________
LM_WLYIA_whichathlete_us
More information about the R-help
mailing list