r - 更快的替代 object.size?

标签 r

除了 object.size 之外,是否存在一种更快的方法来识别对象大小? (或让它执行得更快的方法)?

start.time <- Sys.time()
object.size(DB.raw)
#  5361302280 bytes
Sys.time() - start.time
#  Time difference of 1.644485 mins  <~~~  A minute and a half simply
                                           to show the size

print.dims(DB.raw)
#  43,581,894 rows X 15 cols 

我也想知道为什么计算对象大小需要这么长时间?大概对于每一列,它必须遍历每一行才能找到该列的总大小?

最佳答案

在 Windows 机器上,您可以使用 gc() 获得非常接近的估计值。和 memory.size()创建前后DB.raw .

gc()
x <- memory.size()
# DB.raw created, extra variables rm'ed
gc()
memory.size() - x # estimate of DB.raw size in Mb
# object.size(DB.raw) / 1048576 # for comparison

关于r - 更快的替代 object.size?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19548938/

相关文章:

r - 为什么我使用 Logistic 正则化 glmnet 代码得到 0 和 1 之外的概率?

r - 从较大的栅格堆栈创建栅格堆栈的许多子集

r - 在标题旁边放置 Shiny 的小部件

r - dbConnect with R 3.0 on Ubuntu 12.04 x64 -- as.integer(from) : cannot coerce type 'S4' to vector of type 'integer' 错误

在 dplyr 中重新编码给出错误 : Argument 2 must be named, 未命名

将 HRS 数据从宽格式 reshape 为长格式并创建时间变量

r - 使用 Safely from Purrr 时调试函数?

html - 如何编写一个 R 函数来创建一系列散布有 markdown 的绘图

javascript - 从 plotly 的任何地方 plotly 地点击事件

r - 在控制台与 R markdown 单元中运行时调度的不同打印方法?