我想创建一个分组摘要,报告每个组中的记录数,然后显示一系列变量的含义。如何在一个命令中组合两个不同的dplyr摘要
我只能研究如何做到这两个单独的总结,然后我将它们连接在一起。这工作正常,但我想知道是否有一个更优雅的方式来做到这一点?
dailyn<-daily %>% # this summarises n
group_by(type) %>%
summarise(n=n()) %>%
dailymeans <- daily %>% # this summarises the means
group_by(type) %>%
summarise_at(vars(starts_with("d.")),funs(mean(., na.rm = TRUE))) %>%
dailysummary<-inner_join(dailyn,dailymeans) #this joins the two parts together
我正在使用的数据是这样的数据帧:
daily<-data.frame(type=c("A","A","B","C","C","C"),
d.happy=c(1,5,3,7,2,4),
d.sad=c(5,3,6,3,1,2))
你能分享你的数据样本吗? – Sotos