Skip to contents

It shifts years backwards for correct computation of annual values when the hydrological year does not start in january. Originally created only for internal usage in this pacakge.

Usage

shiftyears(ltime, lstart.month)

Arguments

ltime

vector with the date/times of each element of a zoo object.

lstart.month

numeric in [1,..,12], representing the starting month to be used in the computation of annual values. By default lstart.month=1 (Jan).

Value

Integer vector with the shifted years corresponding to each elemen of x.

Author

Mauricio Zambrano-Bigiarini, mzb.devel@gmail

Examples

# Loading the DAILY precipitation data at SanMartino
data(SanMartinoPPts)
x <- SanMartinoPPts

# Subsetting 'x' to its first three months (Jan/1921 - Mar/1921)
x <- window(x, end="1921-12-31")

# Starting in January, it means no shift
shiftyears(ltime=time(x), lstart.month=1)
#>   [1] 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920
#>  [16] 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920
#>  [31] 1920 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#>  [46] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#>  [61] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#>  [76] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#>  [91] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [106] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [121] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [136] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [151] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [166] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [181] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [196] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [211] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [226] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [241] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [256] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [271] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [286] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [301] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [316] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [331] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [346] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [361] 1921 1921 1921 1921 1921

# Starting in April:
shiftyears(ltime=time(x), lstart.month=4)
#>   [1] 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920
#>  [16] 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920
#>  [31] 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920
#>  [46] 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920
#>  [61] 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920
#>  [76] 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920 1920
#>  [91] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [106] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [121] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [136] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [151] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [166] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [181] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [196] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [211] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [226] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [241] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [256] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [271] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [286] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [301] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [316] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [331] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [346] 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921 1921
#> [361] 1921 1921 1921 1921 1921