Skip to content
Prev 174967 / 398506 Next

Grouping Numbers

Jorge, 

Thank you very much for your post. 

I tried the below with a few modifications:
# First case
N<-100000
X<-rnorm(N)
step_size<-1

# Groups
g<-rep(1:(N/step_size),each=step_size)

# The result
tmp_output<-tapply(X,g,mean)

length_tmp_output<-length(tmp_output)
tmp_x_vals<-rep(step_size,length_tmp_output)
plot(tmp_x_vals, tmp_output)

for(ii in 1:val_size)
{   
step_size<-ii

# Groups
g<-rep(1:(N/step_size),each=step_size)

# The result
tmp_output<-tapply(X,g,mean)

length_tmp_output<-length(tmp_output)
tmp_x_vals<-rep(step_size,length_tmp_output)
points(tmp_x_vals, tmp_output)
}

However, when I change the step_size to 100, I receive the following error:
"Error in tapply(X, g, mean) : arguments must have same length"

Do you have any idea why the for loop crashes?  

I figured it would run smooth since it runs fine prior to the loop. 

Thanks for any insights.
--- On Tue, 3/24/09, Jorge Ivan Velez <jorgeivanvelez at gmail.com> wrote: