getYearsAsINDEX | R Documentation |
Extract the year as a factor (e.g. for computing annual statistics)
getYearsAsINDEX(obj)
obj |
Any object extending the station or grid classes |
The function performs a very basic operation, extracting the year element from the dates previously converted to POSIXlt. The trick lies in the year-crossing seasons. For instance: by convention, winter 2001 encompasses December 2000 and January, February 2001. Therefore, in order to compute annual statistics for a year-crossing season, it is necessary to modify first the vector of years, and assign year 2001 to the preceding December. Similarly, the next December 2001 belongs to winter 2002, and so on... The function is useful for computing and/or plotting annual statistics, seasonal climatologies ...
A vector of years of the same length as the time dimension of the object, seasonally-adjusted in the case of year-crossing seasons (e.g. DJF). See details.
Warning: The function should no be used to extract the vector of actual date years
J. Bedia
Other get.helpers:
get2DmatCoordinates()
,
getCoordinates()
,
getDim()
,
getGrid()
,
getGridProj()
,
getGridVerticalLevels()
,
getRefDates()
,
getSeason()
,
getShape()
,
getStationID()
,
getVarNames()
,
getWT()
,
setGridProj()
,
typeofGrid()
,
which.leap()
require(climate4R.datasets)
data("NCEP_Iberia_hus850")
getSeason(NCEP_Iberia_hus850)
# Winter 1983-2002
range(NCEP_Iberia_hus850$Dates$start)
## Time series for the first point
# Dates vector
time <- as.POSIXlt(NCEP_Iberia_hus850$Dates$start, tz = "GMT")
hus850 <- NCEP_Iberia_hus850$Data[ ,1,1]
plot(time, hus850, ty = "l")
## Computation of the annual series for winter specific humidity:
par(mfrow = c(2,1))
## Wrong:
years <- as.POSIXlt(NCEP_Iberia_hus850$Dates$start)$year + 1900
x <- tapply(hus850, INDEX = list(years), FUN = mean)
plot(unique(years), x, ty = "b")
points(1990, x[1], col = "red", cex = 2, lwd = 2)
## Correct:
years <- getYearsAsINDEX(NCEP_Iberia_hus850)
x <- tapply(hus850, INDEX = years, FUN = mean)
plot(unique(years), x, ty = "b")
par(mfrow = c(1,1))
#Station data:
data("VALUE_Iberia_tas")
getYearsAsINDEX(VALUE_Iberia_tas)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.