-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
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")