Reversing a melting operation with reshape2

r, reshape2

Solution

How could R know the ordering that existed before the melt? i.e. the notion that row one of `x` matches up with row one of `y`.

If you add an index column (since R will complain about duplicated row.names) you can do this operation simply:

dfr$idx <- seq_along(dfr$x)   
mlt <- melt(dfr, id.var='idx')
dcast(mlt, idx ~ variable, value.var='value')

Problem

Consider the following code. ``` library (reshape2) x = rnorm (20) y = x + rnorm (rnorm (20, sd = .01)) dfr <- data.frame (x, y) mlt <- melt (dfr) ``` When I try to reverse this operation with dcast, ``` dcast (mlt, value ~ variable) ``` I get instead a data frame with three columns (not suitable for scatter-plotting, for instance). How can I reenact the original data frame with dcast?

Original source

Related problems