Try this: If cycle.number is ordered:
do.call(rbind, lapply(split(x, x$ID), tail, 1)) On Sat, Sep 12, 2009 at 12:36 PM, caroline choong <carolinevcho...@gmail.com > wrote: > Dear all, > I have a data set as follows: > > ID cycle.number cycle.result > 1 2525 1 38 > 2 2525 2 38 > 3 2525 3 25 > 4 2525 4 25 > 5 2525 5 25 > 6 2525 6 25 > 7 2531 1 38 > 8 2531 2 38 > 9 2078 1 38 > 10 2078 2 38 > > I want to find out the maximum cycle.number for each ID, and later find the > corresponding cycle.result for that cycle. > > I have already managed to pull out the maximum cycle by using a for loop: > > max.cycle <- vector() > patients <- (levels(factor(ID))) > for (i in 1:length(patients)) { > > max.cycle[i] <- max(cycle.number[(ID %in% patients[i] )]) > > } > > But i would like to know if there is a better or more elegant way of > pulling > out the maximum cycle.number for each ID? Perhaps without the need for > using > a for loop? > > Many thanks, > Caroline > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
______________________________________________ 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.