dplyr等同于plyr钻石的例子 [英] dplyr equivalent to ddply in plyr diamonds example
问题描述
t1.table< - ddply(diamonds,c(clarity,cut ),nrow)
我通过清晰度和剪切方式收到钻石计数的汇总表。在dplyr中,我可以想出的最简单的例子是:
diamonds%>%select(clarity,cut)%> ;%group_by(清晰度,剪切)%>%
总结(count = n()) - > t2.table
这似乎有点参与。有没有更好的方式来简化? 〜谢谢
感谢您的帮助。我喜欢这个答案不像原来的ddply命令那么紧凑,但是更容易读取。 (旁注:回答一个问题是一个痛苦,需要工作)
t3.table< - diamonds%>%group_by (清晰度,剪切)%>%summary(nrow = n())
ok, I'm trying to wrap my head around dplyr, using it instead of plyr. In my short time with R I've grown somewhat accustomed to ddply. I'm using a "simple" example for how to use dplyr as opposed to ddply in plyr. Here goes: in the following:
t1.table <- ddply(diamonds, c("clarity", "cut"), "nrow")
I receive a summary table of counts of diamonds by clarity and cut. In dplyr, the simplest example I can come up with is:
diamonds %>% select(clarity, cut) %>% group_by(clarity, cut) %>%
summarise(count=n()) -> t2.table
which seems a bit more involved. Is there a better way to simplify this? ~ thanks
Thanks for the help. I like this answer. Not quite as compact as the original ddply command, but a heck of a lot more readable. (side note: answering a question is a pain, needs work)
t3.table <- diamonds %>% group_by(clarity, cut) %>% summarise(nrow=n())
这篇关于dplyr等同于plyr钻石的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!