X flights.ag <- ddply(worldline, c("AIRPORT_FROM_CODE", "AIRPORT_TO_CODE"), function(x) count(x$AIRPORT_TO_CODE)) 这个是想求每个机场出发的航班数吗? 如果是的话有两点: (1)新的dplyr无法运作上述函数; (2)可以通过data.table快速求出。
X 应该是两个机场间的航线数。可以用下式求出: worldline = as.data.table(worldline) # > unique(worldline) flights.ag <- as.data.frame(worldline[, .N, keyby = c("AIRPORT_FROM_CODE", "AIRPORT_TO_CODE")])
SongKH 感谢作者的辛勤付出。 评论区很多人没有理解作者的意思,作者是用原方法计算了gcircle.rg,改写了另外两个数据集的处理方法。 我附上用作者的方法处理gcircle生成gcircle.rg的代码,仅供参考。 gcircles.mean <- aggregate(x = gcircles[, c("long.recenter")], by = list(gcircles$id), FUN = mean) gcircles.min <- aggregate(x = gcircles[, c("long.recenter")], by = list(gcircles$id), FUN = min) gcircles.max <- aggregate(x = gcircles[, c("long.recenter")], by = list(gcircles$id), FUN = max) gcircles.md <- cbind(gcircles.mean, gcircles.min[, 2], gcircles.max[, 2]) colnames(gcircles.md) <- c("id", "mean", "min", "max") gcirclest <- join(x = gcircles, y = gcircles.md, by = c("id")) gcirclest$id.regroup 180) & (gcirclest$min 180), c("id.regroup")] <- 2 gcirclest$group.regroup <- paste(gcirclest$id, gcirclest$id.regroup, sep = ".") gcircles.rg <- gcirclest