Here, I made a data as simple as possible. id means the personal id number.
In yearmonthweek column , 2012052 means 2nd week of May,2012.
Wt means weight and Ht means height.
data looks like this:
data<-data.frame(id=c(1,1,1,1,1,2,2,2,2,2),
yearmonthweek=c(2012052,2012052,2012052,2012053,2012053,2012051,2012052,2012052,2012052,2012052),
Wt=c(61,60,NA,NA,NA,63,62,62,NA,63),
Ht=c(173,174,174,175,NA,173,174,173,173,174))
I want to make this data weekly basis for each id. That is, within each id, the values of yearmonthweek cannot be duplicated. Also, I want to make extra columns to represent average,max, and mean . My expected output looks like this:
data<-data.frame(id=c(1,1,2,2),
yearmonthweek=c(2012052,2012053,2012051,2012052),
Wt_avg=c(60.5,NA,63,62.333),
Wt_max=c(61,NA,63,63),
Wt_min=c(60,NA,63,62),
Ht_avg=c(173.5,174.5,173,173.667),
Ht_max=c(174,175,173,174),
Ht_min=c(173,174,173,173))