On Feb 4, 2012, at 8:29 PM, dengyu19901102 wrote:

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?


You need to post the results of str(ssta_sst)





   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)]

# As a devugging step you could run this for one of two years and insert:

          print(str(temp))

# to make sure you are not having problems with that assignment
#--
#David.
        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.

______________________________________________
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.

David Winsemius, MD
West Hartford, CT

______________________________________________
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