Here is some sample data on my problem:
mydf <- data.frame(A = rnorm(20, 1, 5),
B = rnorm(20, 2, 5),
C = rnorm(20, 3, 5),
D = rnorm(20, 4, 5),
E = rnorm(20, 5, 5))
Now I'd like to run a one-sample t-test on each column of the data.frame, to prove if it differs significantly from zero, like t.test(mydf$A)
, and then store the mean of each column, the t-value and the p-value in a new data.frame. So the result should look something like this:
A B C D E
mean x x x x x
t x x x x x
p x x x x x
I could definitely think of some tedious ways to do this, like looping through mydf
, calculating the parameters, and then looping through the new data.frame and insert the values.
But with packages like plyr
at hand, shouldn't there be a more concise and elegant way to do this?
Any ideas are highly appreciated.