# Data manipulation problem # Please my Git repo at <https://github.com/markruddy/RAD.git> Running RStudio 0.97.248 The dataset RYA13Report_transect_AB.csv is in a sort of 'longform' at the moment. Which I would like to change so that: 1. Each Pack_Name is a column 2. Each BH_Name is a row 3. Top-mOD are variables of Pack_Name I've played around with reshape but can't fathom it out. Any help appreciated. Mark [[alternative HTML version deleted]]
Just wanted to suggest that you check out the reshape2 package. A lot of folks have complained that R's base reshape() command is rather opaque, and Hadley Wickham wrote his package to facilitate this sort of thing. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." H. Gilbert Welch On Wed, Feb 19, 2014 at 7:18 AM, drruddy gmail <drmarkruddy at gmail.com> wrote:> > # Data manipulation problem # > > Please my Git repo at <https://github.com/markruddy/RAD.git> > > Running RStudio 0.97.248 > > The dataset RYA13Report_transect_AB.csv is in a sort of 'longform' at the moment. Which I would like to change so that: > > 1. Each Pack_Name is a column > 2. Each BH_Name is a row > 3. Top-mOD are variables of Pack_Name > > I've played around with reshape but can't fathom it out. > > Any help appreciated. > > Mark > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at 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. >
You might want to try reading http://vita.had.co.nz/papers/tidy-data.html, which lays out the principles by which you might want to organise your data, matching each task with the appropriate reshape2 function. Hadley On Wed, Feb 19, 2014 at 9:18 AM, drruddy gmail <drmarkruddy at gmail.com> wrote:> > # Data manipulation problem # > > Please my Git repo at <https://github.com/markruddy/RAD.git> > > Running RStudio 0.97.248 > > The dataset RYA13Report_transect_AB.csv is in a sort of 'longform' at the moment. Which I would like to change so that: > > 1. Each Pack_Name is a column > 2. Each BH_Name is a row > 3. Top-mOD are variables of Pack_Name > > I've played around with reshape but can't fathom it out. > > Any help appreciated. > > Mark > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at 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. >-- http://had.co.nz/
library(reshape2) data.melt <- melt(data, id.vars = c('BH_ID', 'BH_Name', 'Pack_Name')) dcast(dm, BH_Name ~ Pack_Name) -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of drruddy gmail Sent: Wednesday, February 19, 2014 7:18 AM To: r-help at r-project.org Subject: [R] Change data format query # Data manipulation problem # Please my Git repo at <https://github.com/markruddy/RAD.git> Running RStudio 0.97.248 The dataset RYA13Report_transect_AB.csv is in a sort of 'longform' at the moment. Which I would like to change so that: 1. Each Pack_Name is a column 2. Each BH_Name is a row 3. Top-mOD are variables of Pack_Name I've played around with reshape but can't fathom it out.?? Any help appreciated. Mark [[alternative HTML version deleted]]