Last active
November 29, 2019 01:36
-
-
Save hrstt/629f17c3a5b6680bad35c871557d2bf5 to your computer and use it in GitHub Desktop.
for chisq.test, convert count data to matrix with tidyverse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
tidyToChisq <- function(data, col, row) { | |
return( | |
data %>% group_by_(col, row) %>% | |
summarise(count = n()) %>% spread(row, count, fill = 0) %>% | |
ungroup() %>% select(-starts_with(col)) %>% as.matrix() %>% chisq.test()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chisq.test()のオプション類はデフォルト値で。引数で指定するオプションがない簡易版。