[R] help required to melt a data frame

Hadley Wickham hadley at rice.edu
Tue May 25 18:27:53 CEST 2010


On Tue, May 25, 2010 at 8:39 AM, Mohan L <l.mohanphy at gmail.com> wrote:
>
>
> On Tue, May 25, 2010 at 6:59 PM, Hadley Wickham <hadley at rice.edu> wrote:
>>
>> > I trying to get a new data frame for 1 bedroom using cast. But I am not
>> > able
>> > to get the below data for 1 Bedroom using cost.
>> >
>> > State  Jan Feb
>> >  xxx   2    0
>> >  yyy   2    2
>> >  zzz   1    0
>>
>> What do those numbers represent?
>>
>> Hadley
>>
>
> The raw data is  real estate & property portal data. the numbers represent
> how many 1 Bedroom house has registered in xxx state on particular months.
> Then we will normalize the data and plot the graph for trend analysis.

In that case, you probably want:

subsets.melt <- melt(subsets.dummy,id.vars=c("State","Bedroom", "Months"))
cast(subsets.melt, State ~ Months, fill = 0, fun = length)

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list