Estoy Corriendo в серии тестов и серии экспорта и архивных текстов. Он обнаружил:
x <- matrix(c(12, 5, 7, 7), ncol = 2)
write.table(chisq.test(table(x)), "x_CHI.txt")
y aparece el siguiente error:
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class ""htest"" to a data.frame
Cualquier ayuda se agradece
Используй ее funciГіn capture.output()
, чтобы мочь спасать результаты в текстовом файле. Используя твой собственный пример:
x <- matrix(c(12, 5, 7, 7), ncol = 2)
resultados <- chisq.test(table(x))
capture.output(resultados, file = "prueba.txt")
Хорошая альтернатива состоит в том, чтобы использовать пакет broom , который преобразовывает многие из объектов R, как они это - chisq.test
, lm
, glm
, ttest
, и т.д. в датирует frame (формат tidy ).
x <- matrix(c(12, 5, 7, 7), ncol = 2)
test <- chisq.test(table(x))
#> Warning in chisq.test(table(x)): Chi-squared approximation may be incorrect
# Como output print
test
#>
#> Chi-squared test for given probabilities
#>
#> data: table(x)
#> X-squared = 0.5, df = 2, p-value = 0.7788
library(broom)
testt <- tidy(test)
# En data frame
testt
#> statistic p.value parameter method
#> 1 0.5 0.7788008 2 Chi-squared test for given probabilities
write.table(testt, "x_CHI.txt")