Hello, helpeRs,
I've been trying, unsuccessfully, to change a dataframe from long to
wide format using reshape (the original). I would appreciate it if
someone could demonstrate the correct syntax. The script below will
create a toy example. The new wide data should have a column name
for each unique entry in the "fame" column. Under each column
should be either the appropriate weight or na, if there is no match.
Thus, the end product should have column names:
valley plot trt 18w 16iso 12:0, etc.
Here is the toy script for the starting data in long form:
dat <- data.frame(fame = gl(4,1,10, labels = c( "18w",
"16iso",
"12:0", "16w")), valley = gl(2,6,10, labels =
c("H", "M")), plot =
gl(5, 2, 10), trt = gl(2,1,10, labels = c("e", "g")), weight
=
1000*runif(10, 0, 1))
Thank you for your assistance.
Toby
Hello, helpeRs,
I've been trying, unsuccessfully, to change a dataframe from long to
wide format using reshape (the original). I would appreciate it if
someone could demonstrate the correct syntax. The script below will
create a toy example. The new wide data should have a column name
for each unique entry in the "fame" column. Under each column
should be either the appropriate weight or na, if there is no match.
Thus, the end product should have column names:
valley plot trt 18w 16iso 12:0, etc.
Here is the toy script for the starting data in long form:
dat <- data.frame(fame = gl(4,1,10, labels = c( "18w",
"16iso",
"12:0", "16w")), valley = gl(2,6,10, labels =
c("H", "M")), plot =
gl(5, 2, 10), trt = gl(2,1,10, labels = c("e", "g")), weight
=
1000*runif(10, 0, 1))
Thank you for your assistance.
Toby
Hi Toby,
I think this should work...
reshape(dat, v.names=c("weight"), idvar=c("valley",
"plot", "trt"),
timevar="fame", direction="wide")
Michael
On 28 September 2010 12:17, Toby Gass <tobygass at
warnercnr.colostate.edu> wrote:> Hello, helpeRs,
>
> I've been trying, unsuccessfully, to change a dataframe from long to
> wide format using reshape (the original). ?I would appreciate it if
> someone could demonstrate the correct syntax. ?The script below will
> create a toy example. ?The new wide data should have a column name
> for each unique entry in the "fame" column. ? Under each column
> should be either the appropriate weight or na, if there is no match.
> Thus, the end product should have column names:
>
> valley ?plot ? trt ? 18w ? 16iso ?12:0, etc.
>
> Here is the toy script for the starting data in long form:
>
> dat <- data.frame(fame = ?gl(4,1,10, labels = c( "18w",
"16iso",
> "12:0", "16w")), valley = gl(2,6,10, labels =
c("H", "M")), plot > gl(5, 2, 10), trt = gl(2,1,10,
labels = c("e", "g")), weight > 1000*runif(10, 0, 1))
>
> Thank you for your assistance.
>
> Toby
>
> ______________________________________________
> 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.
>