Re: [R] Grouping by interval

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Fri, 7 Dec 2007 08:13:20 -0200

Try this:
Vec <- cut(Data[,1], breaks=c(10,15,20,25,30), include=T, right=F) Data <- data.frame(Data, Vec)
aggregate(Data[,2:3], list(Data$Vec), mean)

On 07/12/2007, Sonia Mehault <mehault_at_iim.csic.es> wrote:
> Hello,
>
> I have a dataframe of say 20 lines with one line per individual. I want to group these 20 individuals
> by length class (eg. of 5cm) and get the mean value of all the other variables (eg VarA and VarB) for each length class
>
> My dataframe is as follow:
>
> Length <- 10:30
> VarA <- seq(1000,1200,10)
> VarB <- seq(500,700,10)
> Data <- cbind(Length,VarA,VarB)
>
>
> And I want to get something like:
>
>
> Length Class Mean VarA Mean VarB
> [10-15[ 1020 520
> [15-20[ 1070 570
> [20-25[ 1120 620
> [25-30] 1175 675
>
>
> Would you have any suggestions how to do that ?
> Many thanks.
>
>
> Sonia.
>
> [[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.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
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.
Received on Fri 07 Dec 2007 - 10:16:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 07 Dec 2007 - 11:30:17 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.