【发布时间】:2017-02-23 04:43:50
【问题描述】:
library(ggmosaic)
library(purrr)
library(dplyr)
library(tibble)
library(tidyr)
library(broom)
此问题是对 Jake Kaupp 提供的先前答案的扩展(下面的链接)。
Function for Tidy chisq.test Output for Visualizing or Filtering P-Values
我想将下面的代码转换为使用标准评估的函数,以便我可以跨不同变量创建整齐的 chisq.test 结果。下面的代码在地图行中使用“happy$happy”来查找“happy”变量和其他分类变量之间的关联。该函数允许我将“快乐”更改为另一个变量,例如“健康”或“婚姻”。
我还想在函数中包含最后一个“unnest”行,以便它返回整洁的 chisq.test 结果。
df <- happy %>%
select(-id,-year,-age,-wtssall) %>%
map(~chisq.test(.x,happy$happy))%>%
tibble(names=names(.),data=.) %>%
mutate(stats=map(data,tidy))
unnest(df,stats)
【问题讨论】:
-
我尝试过类似 - Fun%select(-id,-year,-age,-wtssall)%>%map(~chisq.test(. x, Var)%>%tibble(names=names(.),data=.)%>%mutate(stats=map(data,tidy))。我还是标准评估的新手,不知道如何处理purrr::map 函数与 SE 以及“happy$happy”部分一起使用?我在此评论中尝试了示例的变体,但无法正常工作。我知道 dplyr 动词有 SE 版本,但不确定地图还是小标题?
-
当我之前将 SE 与 tidyr 和 dplyr 一起使用时,我使用了 SE 动词,例如,gather 变成了gather_,count 变成了 count_,等等,并为动态变量使用了引号。但是对于这个问题,我不太确定 map 和 tibble 作为 SE,或者在哪里或引用什么?
-
对于第一条评论,我是想写这个...我忘记了 { } Fun%select(-id,-year,-age,- wtssall)%>%map(~chisq.test(.x, Var)%>%tibble(names=names(.),data=.)%>%mutate(stats=map(data,tidy))}.
-
将您尝试的内容添加到问题中。作为评论无法阅读。