[R] Reshape
Michael Bedward
michael.bedward at gmail.com
Tue Sep 28 05:05:15 CEST 2010
I try to remember that timevar defines the wide columns you want and
v.names the values in the body of the table - but I always forget next
time I need to use reshape :)
On 28 September 2010 12:55, Toby Gass <tobygass at warnercnr.colostate.edu> wrote:
> That does work, thank you. I didn't understand that the "fame"
> column would be the time varying column.
>
> Toby
>
> On 28 Sep 2010 at 12:47, Michael Bedward wrote:
>
>> 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.
>> >
>>
>
>
>
More information about the R-help
mailing list