Im a long time SPSS user learning R. I am becoming familiar with different packages & am having some success running different tests.
One problem I am having is when I try and take results from R (either by cut and pasting from console or output.rft functions) - the output is not formatted meaning it is not possible to create a table in either word or excel. Output from several row tends to merge into one cell & I am struggling to know how to reformat it (all standard reformatting options in word & excel do not worked).
Hope this makes sense & any help in getting my results into programmes like excel& word so I can then create tables would be much appreciated.
Can you give some examples of the kind of output you want to transfer to Word or Excel? Is it a data frame/tibble or the summary of a model or something else?
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.