Try this: xtabs(values ~ ind + cover, cbind(cover = propsum$coverClass, stack(propsum)))
On Fri, Apr 23, 2010 at 1:43 AM, <david.gobb...@csiro.au> wrote: > Greetings all, > > I am having difficulty transposing, reshaping, flipping (not sure which) a > data frame which is read from a DBF file. I have tried using t(), reshape() > and other approaches without success. Can anyone please suggest an way > (elegant or not) of flipping this data around ? > > The initial data is like propsum (defined below), and I want it to look > like tpropsum once reformed. > > propsum > coverClass R209120812 R209122212 > 1 C NA 0.05 > 2 G 0.49 0.35 > 3 L 0.38 0.41 > 4 O 0.04 0.09 > 5 S 0.09 0.10 > > > tpropsum > Image C G L O L.1 > 1 R209120812 NA 0.49 0.38 0.04 0.09 > 2 R209122212 0.05 0.35 0.41 0.09 0.10 > > # Example datasets > # Input > propsum <- data.frame(coverClass=c("C", "G", "L", "O", "S"), > R209120812=c(NA, 0.49, 0.38, 0.04, 0.09), > R209122212=c(0.05, 0.35, 0.41, 0.09, 0.10)) > > # Desired output > tpropsum <- data.frame(Image=c("R209120812", "R209122212"), > C=c(NA, 0.05), > G=c(0.49, 0.35), > L=c(0.38, 0.41), > O=c(0.04, 0.09), > L=c(0.09, 0.10)) > > Thanks, > David > > [[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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[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.