# yearly aggregation
#----------------------------------
#long-term monthly temperature of 20 cities
tsl <- tsl_initialize(
x = cities_temperature,
name_column = "name",
time_column = "time"
)
#plot time series
if(interactive()){
tsl_plot(
tsl = tsl[1:4],
guide_columns = 4
)
}
#check time features
tsl_time(tsl)[, c("name", "resolution", "units")]
#aggregation: mean yearly values
tsl_year <- tsl_aggregate(
tsl = tsl,
new_time = "year",
f = mean
)
#' #check time features
tsl_time(tsl_year)[, c("name", "resolution", "units")]
if(interactive()){
tsl_plot(
tsl = tsl_year[1:4],
guide_columns = 4
)
}
# other supported keywords
#----------------------------------
#simulate full range of calendar dates
tsl <- tsl_simulate(
n = 2,
rows = 1000,
time_range = c(
"0000-01-01",
as.character(Sys.Date())
)
)
#mean value by millennia (extreme case!!!)
tsl_millennia <- tsl_aggregate(
tsl = tsl,
new_time = "millennia",
f = mean
)
if(interactive()){
tsl_plot(tsl_millennia)
}
#max value by centuries
tsl_century <- tsl_aggregate(
tsl = tsl,
new_time = "century",
f = max
)
if(interactive()){
tsl_plot(tsl_century)
}
#quantile 0.75 value by centuries
tsl_centuries <- tsl_aggregate(
tsl = tsl,
new_time = "centuries",
f = stats::quantile,
probs = 0.75 #argument of stats::quantile()
)
Run the code above in your browser using DataLab