[R] R - Array data loop selection

dengyu19901102 a1204342 at student.adelaide.edu.au
Sun Feb 5 02:29:43 CET 2012


i want to select June, July and August data from the 3D array (`ssta_sst`,
360*180*362).

the loop works but the output of ssta_winter has the identical values for
`ssta_winter[,,i]`.seen below. I have set it up as an array of (360,180,29).

I think the problem is the variable `temp`, i want to define it as an array
first but i don't know what size it should be (360,180,3) or (360,180,3*29)
and how to keep a loop counter in `temp` when it passes down to finding mean
stage?

   

    ssta_winter = array( data=NA, dim = c(360,180,29))
    temp = array( data=NA, dim = c(360,180,3))
    
    for (yr in 1982:2010) {
    	temp <- ssta_sst[,,year_sst==yr & (month_sst>=6 & month_sst<=8)]
    	for (i in 1:360) {
    		for (j in 1:180) {
    			ssta_winter[i,j,] <- mean(temp[i,j,])
    		}
    	}
    }

    > for (i in 1:29){
    + print(ssta_winter[180,166,i])
    + }
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583
    [1] 0.2222583


--
View this message in context: http://r.789695.n4.nabble.com/R-Array-data-loop-selection-tp4358282p4358282.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list