Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Calculating means for trimesters from an array with monthly values

$
0
0

I have a large array with monthly precipitation values (dimensions=144(longitude)*72(latitude)*395(time)), where time starts at 1979-01-03 (year/month/day) and ends at 2011-11-03.

I need to calculate means and sd, first for each month (i.e. one mean and one sd for each month and each point of the domain). Here's how I did this:

months<-c(as.character(1:12))
years<-c(as.character(1979:2011))
lista<-list()
for (i in months){
  lista[[i]]<-which(format(time2,"%m")==i)   #time2 is the time dimension from the 
                                             # array, in format: 1979-01-03, 1979-02-03,etc.
}
monthly_means<-list(); monthly_sd<-list()
for(i in 1:length(lista)){
  medias_mensuales[[i]]<-apply(precipitacion[,,lista[[i]]],c(1,2),mean)
  sd_mensuales[[i]]<-apply(precipitacion[,,lista[[i]]],c(1,2),sd)
}

and then (this is where I'm having trouble) the means and sd for each trimester (DJF,MAM,JJA,SON). Is it a good idea to first extract each trimester's data and then do something similar to what I did before?


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>