#### take only group 2 values
last.sample(ID="ID", sort.var="group", data=sleep)
#### take only group 1 values
last.sample(ID="ID", sort.var="group", decreasing=FALSE,data=sleep)
#### average group 1 and 2 values
last.sample(ID="ID", data=sleep, FUN=mean, fun.var="extra")
#### take the maximum extra value
last.sample(ID="ID", data=sleep, FUN=max, fun.var="extra")
#### take the mean of two columns extra value
sleep$group = as.numeric(as.character(sleep$group))
last.sample(ID="ID", data=sleep, FUN=mean, fun.var=c("group","extra"))
Run the code above in your browser using DataLab