Tag: plyr data.table

为什么plyr这么慢?

我想我错误地使用plyr。 有人可以告诉我,如果这是“有效的”plyr代码? require(plyr) plyr <- function(dd) ddply(dd, .(price), summarise, ss=sum(volume)) 一个小背景:我有几个大的聚合问题,我已经注意到,他们每个都花了一些时间。 为了解决这个问题,我对R中的各种聚合过程的performance感兴趣。 我testing了一些聚合方法 – 发现自己整天都在等待。 当我终于找回结果的时候,我发现了plyr方法和其他方法之间的巨大差距 – 这让我认为我做了一些错误的事情。 我运行下面的代码(我以为我会在检查新的数据包的时候): require(plyr) require(data.table) require(dataframe) require(rbenchmark) require(xts) plyr <- function(dd) ddply(dd, .(price), summarise, ss=sum(volume)) t.apply <- function(dd) unlist(tapply(dd$volume, dd$price, sum)) t.apply.x <- function(dd) unlist(tapply(dd[,2], dd[,1], sum)) l.apply <- function(dd) unlist(lapply(split(dd$volume, dd$price), sum)) l.apply.x <- function(dd) unlist(lapply(split(dd[,2], dd[,1]), sum)) […]

在data.frame中添加缺失值的行最快的方法?

我在我的数据集中有一列,其中时间段( Time )是从ab到整数。 有时可能会有任何给定的组缺less时间段。 我想用NA填写那些行。 以下是一个(几个1000个)组中的一个的示例数据。 structure(list(Id = c(1, 1, 1, 1), Time = c(1, 2, 4, 5), Value = c(0.568780482159894, -0.7207749516298, 1.24258192959273, 0.682123081696789)), .Names = c("Id", "Time", "Value"), row.names = c(NA, 4L), class = "data.frame") Id Time Value 1 1 1 0.5687805 2 1 2 -0.7207750 3 1 4 1.2425819 4 1 5 0.6821231 […]