my question has a similar one [here][1], but as long dplyr changes the way it does the things, I believe my question is original and could help other people.
First, I'm trying to Inside a function, reports descriptive statistics and run some statistical inference tests, such as chi-square.
This syntax works very well:
> desc_chi <- function(group_var) { group_var <- enquo(group_var) j
> <- dataset %>%
> group_by(!!group_var) %>%
> summarise(n = n()) print(j) }
desc_chi(GENDER)
But when I add a Chi-square test, it stops and reports an error:
desc_chi <- function(group_var) {
group_var <- enquo(group_var)
j <- dataset %>%
group_by(!!group_var) %>%
summarise(n = n(),
pvalue=chisq.test(.$LOCATION, .$group_var))
print(j)
}
Column pvalue
must be length 1 (a summary value), not 9
Thanks for all support you always provide.