Skip to content
Back to formatted view

Raw Message

Message-ID: <f8e6ff050712200936l7de42d9fwb51c7f1fc7da0355@mail.gmail.com>
Date: 2007-12-20T17:36:13Z
From: Hadley Wickham
Subject: Reshape Dataframe
In-Reply-To: <20071220165501.7ABAD300D5@harold.telenet-ops.be>

On Dec 20, 2007 4:56 PM, Bert Jacobs <b.jacobs at pandora.be> wrote:
> Hi,
>
> The problem is probably that my Var4, does not contain number but factor
> information, and therefore I think Gabor's suggestion does not work.
> The same holds for Hadley's solution with the functions melt/cast, where the
> resulting dataframe looks OK, but the dataframe is filled with the number of
> times Var3 occurred for a certain Var1 and a certain Var2. It looks more
> like:
>
> Var1    Var2    W1      W2      W3      W4
> A       Fa      1       1
> A       Si      1               1
> B       Si      1
> C       La              1
> C       Do                              2
>
> While it should be:
>
> Var1    Var2    W1      W2      W3      W4
> A       Fa      F1      F3
> A       Si      F2              F4
> B       Si      F5
> C       La              F6
> C       Do                              F7
> C       Do                              F8
>
> Or even better:
>
> Var1    Var2    W1      W2      W3      W4
> A       Fa      F1      F3
> A       Si      F2              F4
> B       Si      F5
> C       La              F6
> C       Do                              F7/F8

In that case you'll need to specify an aggregation function.  You probably want:

cast(dfm, ... ~ Var3, function(x) paste(x, collapse="/"), add.missing=TRUE)

-- 
http://had.co.nz/