Get `chisq.test()$p.value` for several groups using `dplyr::group_by()`

后端 未结 1 677
执念已碎
执念已碎 2021-01-03 05:51

I\'m trying to conduct a chi square test on several groups within the dplyr frame. The problem is, group_by() %>% summarise() doesn\'t seem to do t

1条回答
  •  星月不相逢
    2021-01-03 06:19

    In dplyr you can generally just use unquoted variable names to access the relevant columns, whether you're in a groupby or otherwise. So removing the .$ accessors from .$partido and .$genero which are not needed I get:

    foo %>% 
        group_by(GM) %>% 
        summarise(pvalue= chisq.test(partido, genero)$p.value) 
    
    # A tibble: 2 × 2
            GM    pvalue
             
    1     Bajo 0.9004276
    2 Muy bajo 0.4777095
    

    0 讨论(0)
提交回复
热议问题