Re: [R] Help in getting aggregated data

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sun 01 Apr 2007 - 05:19:43 GMT

Try this:

aggregate(a[3], a[1:2], max)

On 3/31/07, Deepak Manohar <deepakmanohar@gmail.com> wrote:
> Hi team,
> I have the data of the form:
>
> > a<- data.frame(x=c(1,2,1,4,3), y=c(1,2,1,4,3), z=c(1,2,3,4,5))
>
> I need the output of the form
>
> > b<- data.frame(x=c(1,2,3,4), y=c(1,2,3,4), z=(3,2,5,4) )
>
> As you can see, the Z value contains the maximum for each of the (x,y)
> combinations.
>
> I used
> > c<-by(a$z, list(x=a$x, y=a$y), max)
> > c[,]
> y
> x 1 2 3 4
> 1 3 NA NA NA
> 2 NA 2 NA NA
> 3 NA NA 5 NA
> 4 NA NA NA 4
>
> Not sure If I have any standard function to convert this to the data
> frame that I need. Can you help me convert the last array into the
> data frame? If there is any other way apart from using the "by"
> function, please inform me regarding that as well.
>
> -- Deepak Manohar T
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>



R-help@stat.math.ethz.ch 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. Received on Sun Apr 01 15:22:44 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 01 Apr 2007 - 08:30:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.