I known how to extract the top Nth value using plyr (ddply) as shown below but that is based on sorting and extracting based on one variable... I want to extract based on two variables. how do I do that?
ex.
rats<- read.table("http://vincentarelbundock.github.io/Rdatasets/csv/KMsurv/rats.csv", header=TRUE, sep=",", na.strings="NA", dec=".", strip.white=TRUE)
top = ddply(rats, .(litter), function(x) data.frame(reads=tail(sort(x$time),1)))
the script above works great to extract the top value for each litter but what if I want the top value for each litter by treatment(rx column)?
Any help greatly appreciated.