我有一个大的数据集,R(2.8米行×4列),我试图以转做大量转。我试图使用reshape2 :: cast函数来执行转置,但它的内存不足。故障使用reshape2 ::投功能
问题1:有没有更好的方式做转置?
问题2:我试图砍数据建立成片,做了个转置,然后再组装起来。然而,我遇到了一个关于重组步骤的问题,cbind要求我事先知道我想加入哪些列。有没有一个巧妙的解决这个问题的方法?
bigtranspose<-function(dataset){
n<-nrow(dataset)
i<-1
while (i<=n){
#take 10 rows at a time and do the transpose
UB <- min(i+10, n)
small<-dataset[i:UB,]
smallmelt<-melt(small, id=c("memberID", "merchantID"))
t<-dcast(smallmelt, memberID~merchantID, na.rm=TRUE)
#stack the results together
if (!exists("finaldataset"))
finaldataset<-t
else
finaldataset<-rbind(finaldataset,t)
i <- i+10+1
}
}
是您的数据集矩阵或数据帧? –
尝试'data.table' – Metrics