Depending on the type of tests you're trying to do, I'd suggest that you use broom
in combination with openxlsx
. Then, you would be able to convert tests into a tidy format which could be easily passed to a function that passes a tibble into a .csv or xslx.
Some code:
library(tidyverse)
library(broom)
library(openxlsx)
set.seed(133) # this garantees the example is reproducible
# generating normally distributed vectors
data <- map(1:10, ~rnorm(1000)) # 10 vectors with a 1000 values each
# testing if generated data are normally distributed
tests <- data %>%
map(~ks.test(.x, dnorm))
# generating tidy rows for each test
tidy_tests <- map(tests, tidy) %>%
bind_rows()
# saving tests into an excel file
write.xlsx(tidy_tests, 'tidy_tests.xlsx')
Your .xlsx file would have an output like this one (I'm coping and pasting from the excel file we generated):
statistic |
p.value |
method |
alternative |
0,999746018 |
0 |
One-sample Kolmogorov-Smirnov test |
two-sided |
0,998703017 |
0 |
One-sample Kolmogorov-Smirnov test |
two-sided |
0,997744841 |
0 |
One-sample Kolmogorov-Smirnov test |
two-sided |
0,999707866 |
0 |
One-sample Kolmogorov-Smirnov test |
two-sided |
0,999755772 |
0 |
One-sample Kolmogorov-Smirnov test |
two-sided |
0,992688239 |
0 |
One-sample Kolmogorov-Smirnov test |
two-sided |
0,998981303 |
0 |
One-sample Kolmogorov-Smirnov test |
two-sided |
0,998411468 |
0 |
One-sample Kolmogorov-Smirnov test |
two-sided |
0,999128399 |
0 |
One-sample Kolmogorov-Smirnov test |
two-sided |
0,99744755 |
0 |
One-sample Kolmogorov-Smirnov test |
two-sided |
Of couse, it could be the case your test cannot be easily converted into a tidy format. Take a look at broom
's documentation to be sure.