When I try to use shapiro.test
as a summary function on my R
DataFrame I get the error:
df %>% summarize_all(shapiro.test)
Error: Column `A` must be length 1 (a summary value), not 4
Here is my setup:
df = data.frame(A=sample(1:10,5), B=sample(1:10,5))
df
df %>% summarize_all(mean)
df %>% summarize_all(sd)
df %>% summarize_all(sum)
df %>% summarize_all(shapiro.test)
df$A %>% shapiro.test()
Output:
> df = data.frame(A=sample(1:10,5), B=sample(1:10,5))
> df
A B
1 1 8
2 8 4
3 5 5
4 10 6
5 7 1
> df %>% summarize_all(mean)
A B
1 6.2 4.8
> df %>% summarize_all(sd)
A B
1 3.420526 2.588436
> df %>% summarize_all(shapiro.test)
Error: Column `A` must be length 1 (a summary value), not 4
> df$A %>% shapiro.test()
Shapiro-Wilk normality test
data: .
W = 0.96086, p-value = 0.814
What is special about shapiro.test
that makes it not work vectorized on the columns?