I have checked and I found several questions related to this questions multiple functions in a single tapply or aggregate statement R Grouping functions: sapply vs. lapply vs. apply. vs. tapply vs. by vs. aggregate
Actually I want to know what is the best way to use multiple functions in one of the above mentioned algorithms.
I try to give an example
# make a simple matrix
df <- matrix(data=rnorm(10), 10, 5)
# make a function which calculate several properties
several <- function(x) {
c(min = min(x), mean = mean(x), max = max(x), median =median(x), sum=sum(x))
}
# use one of the apply family
apply(df,2, several)
how would you do that ? is there any other way to make it easier or more practical ?
df
ismatrix
so,apply
works okay. If you need to work withlapply
, convert the dataset todata.frame
Other option would be to usesummarise_each
fromdplyr
– akrun