Hi: Here's a variation on Jim Holtman's solution - same packages.
df <- data.frame(V1 = rep(c('X1', 'X2'), each = 3), V2 = rep(c('Y1', 'Y2', 'Y3'), 2), Y1 = rep(1, 6), Y2 = rep(2, 6), Y3 = rep(3, 6)) dd <- melt(df, id = c('V1', 'V2')) dcast(dd, V2 + variable ~ V1) # A little better... dcast(dd, V2 + variable ~ V1)[, -2] V2 X1 X2 1 Y1 1 1 2 Y1 2 2 3 Y1 3 3 4 Y2 1 1 5 Y2 2 2 6 Y2 3 3 7 Y3 1 1 8 Y3 2 2 9 Y3 3 3 HTH, Dennis On Tue, Jan 18, 2011 at 6:18 PM, pwilliam <pwill...@uoregon.edu> wrote: > > Hi - I'm up against a complicated reshape problem. I have data of the form > > X1,Y1,hr1,hr2,hr3 > X1,Y2,hr1,hr2,hr3 > X1,Y3,hr1,hr2,hr3 > X2,Y1,hr1,hr2,hr3 > X2,Y2,hr1,hr2,hr3 > X2,Y3,hr1,hr2,hr3 > > where X and Y are factors and the hr(1,2,3) are values. I need it as > ,X1, X2 > Y1,hr1,hr1 > Y1,hr2,hr2 > Y1,hr3,hr3 > Y2,hr1,hr1 > Y2,hr2,hr2 > Y2,hr3,hr3 > .., > > Any hints? I've been at it for hours. > > p > > -- > View this message in context: > http://r.789695.n4.nabble.com/Reshape-tp3224455p3224455.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.