[R] Select rows based on condition

kborgmann borgmann at email.arizona.edu
Tue Apr 17 00:51:32 CEST 2012


Hi,
I am relatively new to R and I am trying to figure out how to select rows of
my data based on a condition. 
For example in the dataset below multiple observers recorded data at the
same point on the same date and the data was recorded on separate rows, but
I only need one of the rows of data.  Is it possible to use grep to search
for rows that have matching PtName and Date and then select the row where
ObsID is the smallest with and if statement (i.e., keep the rows with an *
and remove the others)?

PtName  Visit  Date               Obs          ObsID
S2             1      6/8/2005       KB               3           *
S2             1      6/8/2005       JB                 5
S3             1     6/8/2005        KB                3          *
S3             1    6/8/2005         JB                 5       
D1            1     6/12/2007     CD               11
D1            1    6/12/2007       TE                2          *
D1            1    6/12/2007       MB              4

I've tried splitting the data and writing an if...else statement, but have
not been successful.
I greatly appreciate the help.
Thanks Much
Kathi

--
View this message in context: http://r.789695.n4.nabble.com/Select-rows-based-on-condition-tp4562919p4562919.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list