[R] Reporting with down and across variables

hadley wickham h.wickham at gmail.com
Thu Sep 18 17:20:16 CEST 2008


Possibly - in the next version, you'll get a helpful warning message
and cast will take it's best guess at the column that it should use.

Hadley

On Thu, Sep 18, 2008 at 10:15 AM, Matthew Pettis
<matthew.pettis at gmail.com> wrote:
> It does, thanks!  Did I miss in the documentation that the variable
> has to be named 'value'?
>
> On Thu, Sep 18, 2008 at 10:08 AM, hadley wickham <h.wickham at gmail.com> wrote:
>> On Thu, Sep 18, 2008 at 10:03 AM, Matthew Pettis
>> <matthew.pettis at gmail.com> wrote:
>>> [Reposting with changed example]
>>> Hi,
>>>
>>> I want to take the dataframe df generated below and reshape the data with
>>> column names being w, x, y, and the different levels of z.  The values under
>>> the different levels of z are the corresponding values of r.  I've tried
>>> reshape and cast, and I can't seem to find the right combination.  Any help
>>> is appreciated,
>>>
>>> Matt
>>> ---------------------------------
>>>   # Generate data
>>> w <- c("a","b")
>>> x <- c("c","d")
>>> y <- c("e","f")
>>> z <- c("g","h")
>>> df <- expand.grid(w=w,x=x,y=y,z=z)
>>> df$r <- rnorm(16,mean=0,sd=1)
>>
>> Well if you change that last line to :
>>
>> df$value <- rnorm(16,mean=0,sd=1)
>>
>> Then I think the following does what you want:
>>
>> cast(df, w + x + y ~ z)
>>
>> Hadley
>>
>> --
>> http://had.co.nz/
>>
>
>
>
> --
> It is from the wellspring of our despair and the places that we are
> broken that we come to repair the world.
> -- Murray Waas
>



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



More information about the R-help mailing list