data.table聚合操作中的进度条 [英] Progress bar in data.table aggregate action

查看:36
本文介绍了data.table聚合操作中的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ddply 有一个 .progress ,可以在运行时获取进度条,R中的 data.table 是否等效?/p>

ddply has a .progress to get a progress bar while it's running, is there an equivalent for data.table in R?

推荐答案

是的,您可以使用所需的任何进度状态.

Yes, you can use any progress status you want.

library(data.table)
dt = data.table(a=1:4, b=c("a","b"))
dt[, {cat("group:",b,"\n"); sum(a)}, b]
#group: a 
#group: b 
#   b V1
#1: a  4
#2: b  6

如果您询问使用 fread 加载csv文件的进度,则将自动为更大的数据集显示该文件.同样,正如Sergey在评论中提到的那样,您可以使用 verbose 参数在 fread [.data.table "中获取更多信息.

If you ask about progress in loading csv file with fread then it will automatically be displayed for bigger datasets. Also as mentioned by Sergey in comment you can use verbose argument to get more information, both in fread and in [.data.table.

如果要处理的组百分比.

If you want the percentage of groups processed.

grpn = uniqueN(dt$b)
dt[, {cat("progress",.GRP/grpn*100,"%\n"); sum(a)}, b]
#progress 50 % 
#progress 100 % 
#   b V1
#1: a  4
#2: b  6

这篇关于data.table聚合操作中的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆