I posted the following question about two hours ago:
I have a data frame X and a vector Y. Data frame X has columns A, B and
C. Column A of data frame X is as the following: 1, 2, 3, 4, 5. Vector Y
is: 1, 2, 3.
I want to to get the subset of X, which only includes the rows where
column A equals 4 or 5, i.e., the subset of X only contains the rows whose
value in column A is not equal to any elements in vector Y. Besides using
loop, is there an easy way to achieve this? Thanks for your help in advance.
****************************************************************************
***
Thanks to Rod Tjoelker's quick response and help, Rod's solution is as the
following:
X[is.na(match(X$A, Y),]
match returns the indices of values the second vector that match
the values in the first. If a value in the first is not found in
the second, it returns an "NA". We use "is.na" to find those
locations.
---Sharon
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|