Description Usage Arguments Details Value Note Author(s) References See Also Examples
View source: R/extract.monthly.averages.R
need a function to create monthy averages given a set of years
1 | extract.monthly.averages(nc, min.year, max.year)
|
nc |
~~Describe |
min.year |
~~Describe |
max.year |
~~Describe |
give it the nc file from retrieve.nc, min year and max year
...
~~further notes~~
~~who you are~~
~put references to the literature/web site here ~
~~objects to See Also as help
, ~~~
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ## Not run:
##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function(nc,min.year,max.year) {
#ensure nc1 & nc2 are from retrieve.nc
if (all(c('dat','tim','yy','mm', 'lat', 'lon') %in% names(nc))==FALSE)
stop('nc must have objects named dat, lat, lon, tim, yy and mm as from
retrieve.nc of clim.pact package')
#do the work
#track lat, long and time
lat = nc$lat
lon = nc$lon
mm = 1:12
#create an output array
out.data = array(0,dim=c(length(mm),length(lat),length(lon)))
#get the array subset which is from the start year to end year
years = which(nc$yy %in% min.year:max.year)
#cycle through all the data in those years
for (ii in years) out.data[nc$mm[ii],,] = out.data[nc$mm[ii],,] + nc$dat[ii,,]
#now get the average by deviding by the number of months
for (ii in mm) out.data[ii,,] = out.data[ii,,] / (max.year-min.year+1)
#return the information
return(list(dat=out.data,lon=lon,lat=lat,tim=mm))
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.