It seems like a pretty simple question, but I can\'t find the answer.
I have a dataframe (lets call it df
), containing n=100 columns (C1
, <
To apply some function over rows or columns of a data frame, one uses apply
family:
df <- data.frame(a=rnorm(100), b=rnorm(100))
df.shapiro <- apply(df, 2, shapiro.test)
df.shapiro
$a
Shapiro-Wilk normality test
data: newX[, i]
W = 0.9895, p-value = 0.6276
$b
Shapiro-Wilk normality test
data: newX[, i]
W = 0.9854, p-value = 0.3371
Note that column names are preserved, and df.shapiro
is a named list.
Now, if you want, say, a vector of p-values, all you have to do is to extract them from appropriate lists:
unlist(lapply(df.shapiro, function(x) x$p.value))
a b
0.6275521 0.3370931