[R] Reshape, melt and cast query

John Kane jrkrideau at yahoo.ca
Fri Mar 11 00:36:55 CET 2011


I think we need a sample of the orginal data or reasonable facsimile to get an idea of what you are doing.

Have a look at ?dput as a way to provide the data in a handy format.

--- On Thu, 3/10/11, Muzna Alvi <muzna.alvi at gmail.com> wrote:

> From: Muzna Alvi <muzna.alvi at gmail.com>
> Subject: [R] Reshape, melt and cast query
> To: r-help at r-project.org
> Received: Thursday, March 10, 2011, 9:20 AM
> I have a dataset that is based on
> crop output for a single crop
> *sugarcane*...but
> each observation is further subdivided into 3 kinds of
> sugarcane
> i have read the file and have also used melt it to sort it
> on the
> basis of *crop
> group* using
> 
>  melt(sugarcane, m=c("Crop_group")) -> canefile
> 
> this is how it has cast the data
> 
>  variable             
>        value
> 1 Crop_group  Sugarcane (first ratoon)
> 2 Crop_group  Sugarcane (planted crop)
> 3 Crop_group  Sugarcane (planted crop)
> 4 Crop_group Sugarcane (second ratoon)
> 5 Crop_group  Sugarcane (first ratoon)
> 6 Crop_group  Sugarcane (planted crop)
> 
> 
> now i need to *cast *the data so  that i can have each
> of the 20 odd
> variables sorted according to the 3 subdivisions under
> *Crop_group *ie first
> ratoon), second ratoon etc etc..
> 
> i tried using
> 
> cast (canefile, ~value) -> canefile
> 
> but it said "Aggregation requires fun.aggregate: length
> used as default"
> 
> i want to cast it on all the 20 variables and sort it on
> the basis of first
> ratoon, second ratoon and planted crop
> 
> How i do my CAST command?
> 
> I hope my question is clear...thanks in advance
> 
> *
> *
> *
> *
> -- 
> --
> 
>     [[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.
> 





More information about the R-help mailing list