我想創建一個分組摘要,報告每個組中的記錄數,然後顯示一系列變量的含義。如何在一個命令中組合兩個不同的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