[R] reshape from wide to long

hadley wickham h.wickham at gmail.com
Thu Feb 26 05:23:09 CET 2009


On Wed, Feb 25, 2009 at 10:01 PM, Juliet Hannah <juliet.hannah at gmail.com> wrote:
> Out of curiosity, what would be a good way to do this without using
> the reshape package? Thanks!

Well the core of the melt code is this:

    ids <- data[, var$id, drop = FALSE]
    df <- do.call("rbind", lapply(var$measure, function(x) {
        data.frame(ids, x, data[, x])
    }))
    names(df) <- c(names(ids), variable_name, "value")

Hadley

-- 
http://had.co.nz/




More information about the R-help mailing list