Assume a DF of:
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)
Now I need to reshape such that:
require(reshape2)
md <- melt(ht, id = c("pnr", "year"))
output <- dcast(md, pnr ~ value)
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?