Skip to content
Prev 58743 / 398502 Next

Conditional selection of rows

On Tue, 9 Nov 2004, F Z wrote:

            
If you reverse the ordering you are then looking for the first Day in each 
Iteration, which can be done efficiently with duplicated().

data <- data[order(data$Iteration, data$Day, decreasing=TRUE),]

subset <- data[!duplicated(data$Iteration),]

If you are sure that the data are in order to begin with you could just 
reverse the entire data set (  data <- data[nrow(data):1,] ), but I'm 
always reluctant to assume this.

 	-thomas