在数据计算结束后,高效转换 data.table 的好方法是什么?
nrow=500e3
ncol=2000
m <- matrix(rnorm(nrow*ncol),nrow=nrow)
colnames(m) <- c('foo',seq(ncol-1))
dt <- data.table(m)
df <- as.data.frame(m)
dt <- t(dt) #take a long time and converts the data table to a matrix
计算时间
1. to transpose the matrix
system.time(mt <- t(m))
user system elapsed
20.005 0.016 20.024
2. to transpose the dt
system.time(dt <- t(dt))
user system elapsed
32.722 15.129 47.855
3. to transpose a df
system.time(df <- t(df))
user system elapsed
32.414 15.357 47.775
dt[,
10]
应该可以回答你的第二个问题。 - Señor Odata.frame
中进行转置需要多长时间?您的系统有多少内存?仅矩阵本身就需要占用7.4GB的空间。 - Arunmemcpy
)...而你必须重复这个过程5e5次!至少我认为是这样的。 - Arundata.frame
转置需要多长时间?你的系统有多少内存,因为仅矩阵就需要7.4GB的空间? - Arun