The following describes how to use sapply() and lapply() commands to apply functions to return output in the form of vectors and lists respectively:
1. Create Data Frame
x=c(1,2,3,4,5,6,7)
df=data.frame(x)
2. Use sapply to return vectors
sapply(df,mean)
x
4
sapply(df,median)
x
4
sapply(df,sd)
x
2.160247
3. Use lapply to return lists
lapply(df,mean)
$x
[1] 4
lapply(df,median)
$x
[1] 4
lapply(df,sd)
$x
[1] 2.160247


