我有这样的数据
date apps long
10/22/2013 23:51 A 2
10/22/2013 23:52 B 3
10/22/2013 23:52 C 1
10/23/2013 7:03 C 5
10/23/2013 7:13 A 1
10/23/2013 7:31 B 4
10/23/2013 7:31 A 5
10/23/2013 7:31 B 2
10/24/2013 0:54 B 3
10/24/2013 1:16 C 2
10/24/2013 1:16 C 1
10/24/2013 3:27 A 2
10/24/2013 7:30 A 3
10/24/2013 7:30 A 1我遇到的问题是:我想总结一下A,B,C应用程序每天花费的时间。因此,输出将类似于:
A 10/22/2013 2
A 10/23/2013 6
A 10/24/2013 6
etc...我试过一些语法,但没有起作用,谢谢
发布于 2014-07-02 06:50:34
在Using先生的dplyr上使用dd
library(dplyr)
dd%>%
group_by(apps, date=gsub("\\s+.*","",date))%>%
summarize(long=sum(long))
# apps date long
# 1 A 10/22/2013 2
# 2 A 10/23/2013 6
# 3 A 10/24/2013 6
# 4 B 10/22/2013 3
# 5 B 10/23/2013 6
# 6 B 10/24/2013 3
# 7 C 10/22/2013 1
# 8 C 10/23/2013 5
# 9 C 10/24/2013 3https://stackoverflow.com/questions/24523528
复制相似问题