[R] RE SHAPE package question.

hadley wickham h.wickham at gmail.com
Sun Aug 3 00:02:34 CEST 2008


It's called reshape

Hadley

On Sat, Aug 2, 2008 at 4:55 PM,  <rkevinburton at charter.net> wrote:
> I am not there yet. I cannot seem to find the package:
>
>> install.packages("SHAPE")
> Warning in install.packages("SHAPE") :
>  argument 'lib' is missing: using 'F:\Users\Kevin\Documents/R/win-library/2.7'
> Warning message:
> package 'SHAPE' is not available
>
> Is it called something else?
>
> Kevin
>
> ---- hadley wickham <h.wickham at gmail.com> wrote:
>> On Sat, Aug 2, 2008 at 4:00 PM, hpdutra <hpdutra at yahoo.com> wrote:
>> >
>> > I am sorry but here is an example
>> >> test
>> >  t1 t2 t3 t4 M F id
>> > 1  1  0  0  0 1 0  1
>> > 2  1  0  0  0 1 0  1
>> > 3  1  0  0  0 0 1  1
>> > 4  1  0  1  1 1 0  1
>> > 5  1  0  1  1 1 0  1
>> > 6  1  0  1  1 1 0  1
>> > 7  1  0  1  1 0 1  1
>> >
>> >> test<-read.table(h=T, file.choose())
>> >> dfm <- melt(test, m = "id")
>> >> summarised <- cast(dfm, t1+ t2 + t3 + t4 + M + F ~ variable, sum)
>> >> summarised
>> >  t1 t2 t3 t4 M F id
>> > 1  1  0  0  0 0 1  1
>> > 2  1  0  0  0 1 0  2
>> > 3  1  0  1  1 0 1  1
>> > 4  1  0  1  1 1 0  3
>> >
>> >
>> >
>> > So it works partially because it does not add the male and females columns.
>> > I am sure it is simple but I just don't know how to do it. I was hoping that
>> > it would give me the following data
>>
>> I think that you need to treat M and F as measured variables as well:
>>
>> dfm <- melt(test, m = c("id", "M", "F"))
>>
>> Then the same cast command will get you the format that you want.
>>
>> Hadley
>>
>> --
>> http://had.co.nz/
>>
>> ______________________________________________
>> 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.
>
>



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



More information about the R-help mailing list