Convert time-slices to date-time, extract year, month, day of the year, or hour
Source:R/timeslices.R
tsl2dtm.Rd
Convert time-slices to date-time, extract year, month, day of the year, or hour
Usage
tsl2dtm(
tsl,
format = tsl_guess_format(tsl),
tmz = "UTC",
year = NULL,
mday = NULL
)
tsl2year(tsl, return.null = T)
tsl2yday(tsl, return.null = T)
tsl2hour(tsl, return.null = T)
tsl2month(tsl, format = tsl_guess_format(tsl), return.null = T)
Arguments
- tsl
character vector with time slices
- format
character, the time slices format
- tmz
time-zone
- year
year, used when time-slices don't store year
- mday
day of month, for time slices without the information
- return.null
logical, valid for the cased then all values are NA, then NULL will be returned if return.null = TRUE,
Functions
tsl2year()
: Extract year from time-slicestsl2yday()
: Extract the day of the year from time-slicestsl2hour()
: Extract hour from time-slicestsl2month()
: Extract month from time-slices
Examples
tsl <- c("y2007_d365_h15", NA, "d151_h22", "d001", "m10_h12")
tsl2dtm(tsl[1])
#> [1] "2007-12-31 15:00:00 UTC"
tsl2dtm(tsl[1:2])
#> Warning: 1 failed to parse.
#> [1] "2007-12-31 15:00:00 UTC" NA
tsl2dtm(tsl[2])
#> NULL
tsl2dtm(tsl[3])
#> NULL
tsl2dtm(tsl[4])
#> NULL
tsl2dtm(tsl[3], year = 2010)
#> [1] "2010-05-31 22:00:00 UTC"
tsl2dtm(tsl[4], year = 1900)
#> [1] "1900-01-01 UTC"
tsl2dtm(tsl[3:4], year = 1900)
#> NULL
tsl2year(tsl)
#> [1] 2007 NA NA NA NA
tsl
#> [1] "y2007_d365_h15" NA "d151_h22" "d001"
#> [5] "m10_h12"
tsl2yday(tsl)
#> [1] 365 NA 151 1 NA
tsl
#> [1] "y2007_d365_h15" NA "d151_h22" "d001"
#> [5] "m10_h12"
tsl2hour(tsl)
#> [1] 15 NA 22 NA 12
tsl2month(c("d001_h00", "d151_h22", "d365_h23"))
#> [1] 1 5 12
tsl2month(c("m01_h12", "m05_h02", "m10_h01"))
#> [1] 1 5 10