[R] Identifying last record in individual growth data over different time intervalls

Chris Stubben stubben at lanl.gov
Mon Mar 5 18:37:14 CET 2007


> Finally I would like to have a data.frame t2 which only contains the 
> entries of the last measurements.
> 

You could also use aggregate to get the max year per plate then join that back
to the original dataframe using merge on year and plate (common columns in both
dataframes).



x<-data.frame(id=(1:8), plate=c(15,15,15,20,20,33,43,43),
year=c(2004,2005,2006,2004,2005,2004,2005,2006), 
height=c(0.40,0.43,0.44,0.90,0.94,0.15,0.30,0.38))

merge(x, aggregate(list(year=x$year), list(plate=x$plate), max))


  plate year id height
1    15 2006  3   0.44
2    20 2005  5   0.94
3    33 2004  6   0.15
4    43 2006  8   0.38



More information about the R-help mailing list