[R] Question about subsetting data

Moshe Olshansky m_olshansky at yahoo.com
Wed Jun 4 03:09:58 CEST 2008


One possibility is:

x <- ceiling((1:100)/10)
aggregate(var1,by=list(x),mean)


--- On Wed, 4/6/08, William Pepe <williampepe at hotmail.com> wrote:

> From: William Pepe <williampepe at hotmail.com>
> Subject: [R] Question about subsetting data
> To: r-help at r-project.org
> Received: Wednesday, 4 June, 2008, 10:35 AM
> I have a data set(Bill) of with 1 variable (var1), with 100
> obs that are in ascending order. I want to sample every 10
> observations and save them in 10 different groups such as
>  
>   Group1 is obs 1-10
>   Group 2 is obs-11-20
>  
> and so on.
>  
> First step is to subset them into the 10 groups, then
> calculate the mean of var1 for each of the 10 groups. Any
> help would be appreciated. Thanks.
>  
> _________________________________________________________________
> 
> 
> sh_skydrive_062008
> 	[[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