jholtman at gmail.com
Wed Jan 19 05:20:05 CET 2011
This gets you close; just edit the row names:
> x <- read.table(textConnection("X1,Y1,hr1,hr2,hr3
+ X2,Y3,hr1,hr2,hr3"), sep = ',', as.is = TRUE)
> x.m <- melt(x, id = c('V1', 'V2'), stringsAsFactors = FALSE)
> t(cast(x.m, V1 ~ V2, fun = as.character))
Y1_X1 "hr1" "hr1"
Y1_X2 "hr2" "hr2"
Y1_X3 "hr3" "hr3"
Y2_X1 "hr1" "hr1"
Y2_X2 "hr2" "hr2"
Y2_X3 "hr3" "hr3"
Y3_X1 "hr1" "hr1"
Y3_X2 "hr2" "hr2"
Y3_X3 "hr3" "hr3"
On Tue, Jan 18, 2011 at 9:18 PM, pwilliam <pwilliam at uoregon.edu> wrote:
> Hi - I'm up against a complicated reshape problem. I have data of the form
> where X and Y are factors and the hr(1,2,3) are values. I need it as
> ,X1, X2
> Any hints? I've been at it for hours.
> 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 at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Data Munger Guru
What is the problem that you are trying to solve?
More information about the R-help