[R] Grouping Numbers
Jason Rupert
jasonkrupert at yahoo.com
Wed Mar 25 03:52:34 CET 2009
Ugh...This should be very simple, but evidently I am not searching for the proper term.
Given the below:
val_size<-100000
x_vals<-rnorm(val_size)
I would like to group them according to the following
x_vals_mean_tmp[1]<-mean(x_vals[1:10])
x_vals_mean_tmp[2]<-mean(x_vals[11:20])
...
x_vals_mean_tmp[n]<-mean(x_vals[99991:100000])
Then,
I would like to group them according to the following
x_vals_mean_tmp[1]<-mean(x_vals[1:100])
x_vals_mean_tmp[2]<-mean(x_vals[101:200])
...
x_vals_mean_tmp[m]<-mean(x_vals[99901:100000])
etc.
I'm pretty sure I can come up with a loop to do this, but wondering if there is something that will allow me to break up the x_vals vector according to a certain step size. I looked at split and cut, but those did not appear to accomplish what is needed.
Thanks again.
More information about the R-help
mailing list