本文介绍了dcast用于巨大的数据帧[R]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假定DF为:

    pnr <- c(1, 1, 1, 2, 2, 3, 4, 5, 5)
    diag <- c("a", "a", NA, "b", "a", NA, "c", "a", "f")
    year <- rep(2007, 9)
    ht <- data.frame(pnr, diag, year)

现在我需要重塑:

    require(reshape2)
    md <- melt(ht, id = c("pnr", "year"))
    output <- dcast(md, pnr ~ value)

输出现在是我想要的格式.但是,当我在1300万行的大型数据帧上运行此命令时,它将使R-studio崩溃.是否有一些聪明的方法来拆分数据帧,执行dcast并重新绑定?

Output is now in the format I want. But when I run this on a large data frame, 13million rows, it will crash R-studio. Is there some smart way to split a dataframe, do the dcast, and tie back?

以下发布的解决方案在这种情况下无法使用,因为我无法安装.当然有某种方法可以解决此问题?

EDIT : The solutions posted below, will not work in this case, as I not able to install. Surely there is some way to work around this?

推荐答案

对于这种情况,最简单的解决方法是切换回旧的reshape程序包.这意味着使用强制转换而不是dcast.只要可以实际更新,Arun的评论就非常有用.相关

The easy solution to this case turned out to be switching back to the old reshape package. Which means useing cast instead of dcast. Arun's comments are highly usable, providede one can actually update.Related

这篇关于dcast用于巨大的数据帧[R]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 07:48