using the purrr
package
map(sample, function(x) shapiro.test(rnorm(x)))
which gives
[[1]]
Shapiro-Wilk normality test
data: rnorm(x)
W = 0.92567, p-value = 0.4067
[[2]]
Shapiro-Wilk normality test
data: rnorm(x)
W = 0.95621, p-value = 0.247
[[3]]
Shapiro-Wilk normality test
data: rnorm(x)
W = 0.96144, p-value = 0.1021
[[4]]
Shapiro-Wilk normality test
data: rnorm(x)
W = 0.98654, p-value = 0.4077
[[5]]
Shapiro-Wilk normality test
data: rnorm(x)
W = 0.99597, p-value = 0.2324
Edit: so after your edit you are requesting some table. This doesn't work in the way you are doing it with your replicate_sw10 example as that is a matrix, while map (or lapply for that matter) results in a list. So again you want to use apply or map to do the same transformations on all the parts of the list.
replicate_swall <- map(sample, function(x) shapiro.test(rnorm(x)))
replicate_pvalue_extract <- map(replicate_swall , function(x) x["p.value",]) %>% unlist(., recursive = F)
table(replicate_pvalue_extract < 0.10) / length(replicate_pvalue_extract )
This will give you:
FALSE TRUE
0.896 0.104
Another option is using the magrittr
package for the extract. Your code will than look like
replicate_pvalue_extract <- map(replicate_swall, magrittr::extract, "p.value") %>% unlist(., recursive = F)
table(replicate_pvalue_extract < 0.10) / length(replicate_pvalue_extract )
In the code above I assumed that you wanted to divide your table by all replicates and that it doesn't matter what the input was (with input I mean 10,30,50,100, or 500) . If you do care about the input you can keep them separate, I will give the code below. Also note that I used length rather than your hardcoded /1000. In this way your code is way more generic, if you change the replicate number the number you divide your table with automatically changes as well. Otherwise you have to make the changes on multiple locations (especially if someone else uses your code) which could easily result in mistakes.
replicate_pvalue_extract <- map(replicate_swall , function(x) x["p.value",])
map(replicate_pvalue_extract , function(x) table(x < 0.10) / length(x))
Or you can combine them:
map(map(replicate_swall, function(x) x["p.value",]), function(x) table(x < 0.10) / length(x))
This is why I gave you the magrittr option, as I do not like the function(x) twice. With magrittr it would look like:
map(map(replicate_swall, magrittr::extract, "p.value"), function(x) table(x < 0.10) / length(x))
which would result in:
[[1]]
FALSE TRUE
0.896 0.104
[[2]]
FALSE TRUE
0.889 0.111
[[3]]
FALSE TRUE
0.904 0.096
[[4]]
FALSE TRUE
0.9 0.1
[[5]]
FALSE TRUE
0.891 0.109