Skip to content
Back to formatted view

Raw Message

Message-ID: <971536df0902212106h53dd8db7ra19ecc31b3dc5a9d@mail.gmail.com>
Date: 2009-02-22T05:06:29Z
From: Gabor Grothendieck
Subject: How to reshape this data frame from long to wide ?
In-Reply-To: <42d0a5730902211923v2a0a4d56i7dc05bcad5baf235@mail.gmail.com>

Not completely clear what you want (it does not appear to be a
conventional reshape) but try this:

> m <- matrix(c("A", "A", "B", "1", "2", "3"), 3, 2)
> structure(do.call(cbind, lapply(tapply(m[,2], m[,1], c), ts)), tsp = NULL, class = NULL)
     A   B
[1,] "1" "3"
[2,] "2" NA


On Sat, Feb 21, 2009 at 10:23 PM, Daren Tan <darentan76 at gmail.com> wrote:
> I tried cast and melt in reshape package, but still can't convert this data
> frame m
>
> m
>     [,1] [,2]
> [1,] "A"  "1"
> [2,] "A"  "2"
> [3,] "B"  "3"
> to this form.
>
> m1
>     [,1] [,2]
> [1,] "A"  "B"
> [2,] "1"  "3"
> [3,] "2"  NA
> Please help.
>
>        [[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.
>