我有以下问题: 我有下表:
> data
StartPoint EndPoint timeDiff
1 A91 TX043 258
2 A91 TX048 547
3 A92 TX088 330
4 A91 TX088 289
5 A91 TX043 387
6 A92 TX088 241
7 A91 TX088 213
8 A92 TX043 295
9 A91 TX088 518
10 A92 TX088 414
我需要以下形式的聚合:
StartPoint EndPoint count mean(timeDiff)
A91 TX088 3 mean of 289,213 and 518
A91 TX043 2 mean of 258 and 387
A91 TX048 1 547
A92 TX088 3 mean of 330, 241 and 414
A92 TX043 1 295
count 是相同 StartPoint 和 EndPoint 对的出现次数,mean 是具有相同 StartPoint 和 EndPoint 对的条目的 timeDiff 的平均值。结果应按 StartPoint、count 和 EndPoint 排序。
任何帮助将不胜感激。
提前致谢, 杉
我的数据:
data <- structure(list(StartPoint = c("A91", "A91", "A92", "A91", "A91", "A92", "A91", "A92", "A91", "A92"), EndPoint = c("TX043", "TX048", "TX088", "TX088", "TX043", "TX088", "TX088", "TX043", "TX088", "TX088"), timeDiff = c(258, 547, 330, 289, 387, 241, 213, 295, 518, 414)), .Names = c("StartPoint", "EndPoint", "timeDiff"), row.names = c(NA, 10L), class = "data.frame")