On Mar 25, 2010, at 9:21 PM, tj wrote:


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

Consider:

> ygrp <- matrix(y, ncol=3, byrow=TRUE)
> ygrp
      [,1] [,2] [,3]
 [1,]  2.4  2.4  2.4
 [2,]  2.2  2.1  1.5
 [3,]  2.3  2.3  2.5
 [4,]  2.0  1.9  1.7
 [5,]  2.2  1.8  3.2
 [6,]  3.2  2.7  2.2
 [7,]  2.2  1.9  1.9
 [8,]  1.8  2.7  3.0
 [9,]  2.3  2.0  2.0
[10,]  2.9  2.9  2.7
[11,]  2.7  2.3  2.6
[12,]  2.4  1.8  1.7
[13,]  1.5  1.4  2.1
[14,]  3.3  3.5  3.5
[15,]  3.1  2.6  2.1
[16,]  3.4  3.0  2.9

> ygrp[16, ]
[1] 3.4 3.0 2.9

--
David.

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.

______________________________________________
R-help@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.

______________________________________________
R-help@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.

Reply via email to