I couldn't a find a solution so far ... I have a data frame X of 7 colums. I want to get statistical data from colums 6 and 7 which are collected in a matrix. I would like to use one line of code for that issue. I need a function wich takes colum 6 and 7 of data frame X and calculates mean, var, sd, ...
The code I have used is this one:
matrix(c(mean(X$6), mean(X$6, trim = 0.05), var(X$6), sd(X$6),
mean(X$7), mean(X$7, trim = 0.05), var(X$7), sd(X$7)),
nr = 4, dimnames = list(c("mean", "meanTrim", "var", "sd"),
c("WorkTime", "TransTime")))
It works but it seems to be quite awkward. Do you know a shorter solution?
You could do something like:
Y <- sapply(X[, 6:7], function(i) c(mean(i), mean(i, trim = 0.05), var(i), sd(i)))
dimnames(Y) <- list(c("mean", "meanTrim", "var", "sd"), c("WorkTime", "TransTime"))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments