I would like to find the minimum SkinTemp value and the corresponding Time when it occurs for each id.
df<-data.frame(Time=seq(65),
SkinTemp=rnorm(65,37,0.5),
id=rep(1:10,c(5,4,10,6,7,8,9,8,4,4)))
I have successfully found the minimum value for each group but can't quite work out how to find the corresponding Time:
a<-aggregate(data=df,SkinTemp~id, min)
or
df %>% group_by(id) %>% summarise(minSkinTemp = min(SkinTemp))
I'm missing something like which.min
, but I haven't found any examples of this being used with aggregate. Any thoughts?