extract.monthly.averages: Extract Monthly Longterm Climate Averages

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/extract.monthly.averages.R

Description

need a function to create monthy averages given a set of years

Usage

1
extract.monthly.averages(nc, min.year, max.year)

Arguments

nc

~~Describe nc here~~

min.year

~~Describe min.year here~~

max.year

~~Describe max.year here~~

Details

give it the nc file from retrieve.nc, min year and max year

Value

...

Note

~~further notes~~

Author(s)

~~who you are~~

References

~put references to the literature/web site here ~

See Also

~~objects to See Also as help, ~~~

Examples

 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)

jjvanderwal/climates documentation built on May 19, 2019, 11:41 a.m.