Hello,

Try

df1 <- read.table(text="
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
", header=TRUE)
head(df1)

df2 <- with(df1, sapply(split(df1, list(PtName, Date)),
                                     function(x) if(nrow(x)) x[which(x$ObsID ==
min(x$ObsID)), ]))
df2 <- do.call(rbind, df2)
rownames(df2) <- 1:nrow(df2)
df2

Hope this helps,

Rui Barradas


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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to