0

Inspired by this question, Get `chisq.test()$p.value` for several groups using `dplyr::group_by()` I am doing Chi-squared tests over a few groups but I need to customize the default chisq.test arguments but I got an error. Please see how I could improve my code. Thank you

data%>%
  group_by(col4,col5)%>%
  do(broom::tidy(chisq.test(x=(.$col1, .$col2),simulate.p.value = T)))

It seems to me that multiple arguments are not allowed. The error I got was

 Error: unexpected ',' in:
"  group_by(col4,col5)%>%
  do(broom::tidy(chisq.test(x=(.$col1,"

The default works fine.

data%>%
      group_by(col4,col5)%>%
 do(broom::tidy(chisq.test(.$col1, .$col2)))
hnguyen
  • 772
  • 6
  • 17
  • 2
    `(.$col1, .$col2)` is not valid code. You can see this is exactly where the code breaks in the error message - where you try to add a comma and specify `.$col2`. Did you mean `c(.$col1, .$col2)` ? or `cbind(.$col1, .$col2)` ? – thelatemail Nov 21 '19 at 23:13
  • Thanks, that solves my problem. My bad. – hnguyen Nov 21 '19 at 23:18
  • 3
    Don't feel bad, we all make typos and miss little things from time to time. Just make sure you are getting the result you expect compared to the version of your code that is working. You could also use `do(broom::tidy(chisq.test(x=.$col1, y=.$col2)))` I think. – thelatemail Nov 21 '19 at 23:21
  • Thanks for your explanation and for being forgiving. – hnguyen Nov 21 '19 at 23:26

0 Answers0