Taken from here:
require(data.table)
dt <- data.table(subj = c(1,1,2,2,2), code = c("a", "b", "a", "d", "e"))
To use dcast, we need an awkward intermediate step:
dt[, grp := paste("var", seq_len(.N), sep=""), by=subj]
and then do:
dcast(dt, subj ~ grp, value.var="code")
Instead, it should be possible to do:
dcast(dt, subj ~ rowid(subj, prefix="var"), value.var="code")
Also update this SO post linked in #1205.
Taken from here:
To use
dcast, we need an awkward intermediate step:and then do:
Instead, it should be possible to do:
Also update this SO post linked in #1205.