Taken from [here](http://stackoverflow.com/questions/32721106/structure-r-dataframe-from-long-to-wide/32721160#32721160): ``` r 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: ``` r dt[, grp := paste("var", seq_len(.N), sep=""), by=subj] ``` and then do: ``` r dcast(dt, subj ~ grp, value.var="code") ``` Instead, it should be possible to do: ``` r dcast(dt, subj ~ rowid(subj, prefix="var"), value.var="code") ``` Also update [this SO](http://stackoverflow.com/a/31194461/559784) post linked in #1205.
Activity
[-]need 'grpid()' like 'rleid()'[/-][+]need 'rowid()' like 'rleid()'[/+]MichaelChirico commentedon Sep 24, 2015
I guess this halfway sort of takes care of #1206 as well, if I'm not mistaken.
And there's probably 30 SO answers that could use this! Let me see if I can dig some up.