Hello,
If I understand it correctly, this could be formatted as two separate data's for VWC and Tair as the row numbers differ after reshaping. #VWC toymelt1<-melt(toy[,7:11]) colnames(toymelt1)<-c("VWC","VWC_Response") dat2<-data.frame(Group=c(rep("B",80),rep("T",120)), Subject=c(rep(1,40),rep(2,40),rep(1,40),rep(2,40),rep(10,40))) toynewVWC<-data.frame(dat2,toymelt1) #Tair toymelt2<-melt(toy[,12:15]) colnames(toymelt2)<-c("Tair","Tair_Response") dat3<-data.frame(Group=c(rep("B",80),rep("T",80)), Subject=c(rep(1,40),rep(2,40),rep(1,40),rep(2,40))) toynewTair<-data.frame(dat3,toymelt2) Hope this helps. A.K. ----- Original Message ----- From: nrm2010 <nrm2...@zoho.com> To: r-help <r-help@r-project.org> Cc: Sent: Wednesday, June 20, 2012 12:08 PM Subject: [R] reshape Hello, helpeRs, I am attempting to reshape (either base R or package reshape) multiple .csv spreadsheets from a very unfortunate wide format to long format. Each spreadsheet looks something like this, after being read in to R: toy <- data.frame(year = rep(2007:2008,each = 20), month = rep(1:5,each = 4, length = 40), day = rep(1:2,each = 2,length = 40), hhmm = rep(1100:1101,length = 40), plot = rep(1,40), trt=rep(4,40), VWC.B1 = rnorm(40), VWC.B2 = rnorm(40), VWC.T1 = rnorm(40), VWC.T2 = rnorm(40), VWC.T10 = rnorm(40), Tair.B1 = rnorm(40),Tair.B2 = rnorm(40), Tair.T1 = rnorm(40), Tair.T2 = rnorm(40)) Taken together, the columns year, month, day, and hhmm define a timepoint at which at a measurement was taken. Plot and treatment do not change within any one spreadsheet. Parsing the column names, VWC and Tair are 2 different types of measurements; in the full dataset, there are more than 2 types of measurements. The B and T in the column names are grouping variables. The numbers following the B or T are subjects within groups. So, if a column name is VWC.B1, it is the VWC measurement taken on subject 1 within group B. I am trying to reshape to long format. The long format should have one new column for each measurement type (VWC and Tair in the toy example), a new column indicating the grouping variable (B or T), and a new column identifyng the subject (the number that follow the B or T). I've been unable to come up with a solution that produces the group and subject within group columns as well as both types of measurements. Any assistance would be greatly appreciated. Thank you. Toby Toby Gass, Ph.D. Visiting Lecturer, Forestry and Wildland Resources Humboldt State University email: toby.gass <at> humboldt <dot> edu ______________________________________________ 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. ______________________________________________ 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.