For each unique id, I'd like to calculate the maximum difference between each value of SkinTemp using lapply (or aggregate) of a series of curves (Time,SkinTemp) designated by a unique id in a data.frame.
So far I have the following but it returns a single value which is not right:
df<-data.frame(Time=seq(100),
SkinTemp=rnorm(100,37,0.5),
id=rep(1:10,each=10))
maxDiff<-function(id,df) {
a<-max(diff(df$SkinTemp))
a
}
maxA<-lapply(id,maxDiff,df)
Any thoughts on why it doesn't retrieve a unique max value of SkinTemp for each id?
Edit:
Using aggregate no problem (I think it's ddplyr package)
aggregate(data=df,SkinTemp~id,function(x)max(diff(x)))
So what am I doing wrong with lapply?