小编Ana*_*and的帖子

是否()函数生成增长列表

by函数是否生成一次只增长一个元素的列表?

我需要处理一个数据框,其中大约有4M观测值按因子列分组.情况类似于以下示例:

> # Make 4M rows of data
> x = data.frame(col1=1:4000000, col2=10000001:14000000)
> # Make a factor
> x[,"f"] = x[,"col1"] - x[,"col1"] %% 5
>   
> head(x)
  col1     col2 f
1    1 10000001 0
2    2 10000002 0
3    3 10000003 0
4    4 10000004 0
5    5 10000005 5
6    6 10000006 5
Run Code Online (Sandbox Code Playgroud)

现在,tapply其中一个列需要一段合理的时间:

> t1 = Sys.time()
> z = tapply(x[, 1], x[, "f"], mean)
> Sys.time() - t1
Time difference …
Run Code Online (Sandbox Code Playgroud)

benchmarking r tapply

7
推荐指数
1
解决办法
173
查看次数

标签 统计

benchmarking ×1

r ×1

tapply ×1