[R] reshape data from long to wide format

maxbre mbressan at arpa.veneto.it
Fri Sep 9 13:28:15 CEST 2011

This is my reproducible example:

example<-structure(list(SENSOR = structure(1:6, .Label = c("A", "B", "C", 
"D", "E", "F"), class = "factor"), VALUE = c(270, 292.5, 0, 45, 
247.5, 315), DATE = structure(1:6, .Label = c(" 01/01/2010 1", 
" 01/01/2010 2", " 01/01/2010 3", " 01/01/2010 4", " 01/01/2010 5", 
" 01/01/2010 6"), class = "factor")), .Names = c("SENSOR", "VALUE", 
"DATE"), class = "data.frame", row.names = c("1", "2", "3", "4", 
"5", "6"))

I need to resahpe "example"  in a wide format so that “SENSOR” appear as
columns and “DATE” as rows with corresponding “VALUE” as value;

I thought it was very simple so that I’ve been trying this:


But I've got this message:

Using DATE as value column.  Use the value argument to cast to override this
Errore in `[.data.frame`(data, , variables, drop = FALSE) : 
  undefined columns selected

and even if by using the value argument sorted out any good result…

sorry for the very trivial question, I've been looking at documentation and
forums anywhere but I was not successful at all and now I’m somehow in the
right middle of nowhere…

any help or hint for this?

thank you


View this message in context: http://r.789695.n4.nabble.com/reshape-data-from-long-to-wide-format-tp3801381p3801381.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list