[R] Create blocks or observations

tj girlme80 at yahoo.com
Fri Mar 26 02:21:22 CET 2010


Anyone who can help me with this?
I have 48 observations (I dont want to alter their order). I want to group
these observations into 16 blocks. So I should have 3 observations for each
block. This is what I did in R, but it has warnings. 

> y                 #contains my 48 observations
 [1] 2.4 2.4 2.4 2.2 2.1 1.5 2.3 2.3 2.5 2.0 1.9 1.7 2.2 1.8 3.2 3.2 2.7 2.2
2.2
[20] 1.9 1.9 1.8 2.7 3.0 2.3 2.0 2.0 2.9 2.9 2.7 2.7 2.3 2.6 2.4 1.8 1.7 1.5
1.4
[39] 2.1 3.3 3.5 3.5 3.1 2.6 2.1 3.4 3.0 2.9
> g=c(0,0,0)         #storage vector
> for (i in 1:16){  
+ g[i]=y[(3*i-2) : (3*i)]
+ }
There were 16 warnings (use warnings() to see them)
> g[1]
[1] 2.4
> g[2]
[1] 2.2
> 

###### g[1] should show 2.4 2.4 2.4
###### g[2] should show 2.2 2.1 1.5
######g[16] should show 3.4 3.0 2.9

Can you please tell me how I should correct my program?
Thank you.

~tj

-- 
View this message in context: http://n4.nabble.com/Create-blocks-or-observations-tp1691606p1691606.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list