
Last chance! 50% off unlimited learning
Sale ends in
#generate irregular time series
tsl <- tsl_simulate(
n = 2,
rows = 100,
irregular = TRUE
)
if(interactive()){
tsl_plot(tsl)
}
#range of times between samples
tsl_time_summary(tsl)[
c(
"units",
"resolution_min",
"resolution_max"
)
]
#resample to regular using linear interpolation
tsl_regular <- tsl_resample(
tsl = tsl
)
if(interactive()){
tsl_plot(tsl_regular)
}
#check new resolution
tsl_time_summary(tsl_regular)[
c(
"units",
"resolution_min",
"resolution_max"
)
]
#resample using keywords
#valid resampling keywords
tsl_time_summary(
tsl = tsl,
keywords = "resample"
)$keywords
#by month
tsl_months <- tsl_resample(
tsl = tsl,
new_time = "months"
)
if(interactive()){
tsl_plot(tsl_months)
}
#by week
tsl_weeks <- tsl_resample(
tsl = tsl,
new_time = "weeks"
)
if(interactive()){
tsl_plot(tsl_weeks)
}
#resample using time interval
#get relevant units
tsl_time(tsl)$units
#resampling to 15 days intervals
tsl_15_days <- tsl_resample(
tsl = tsl,
new_time = 15 #days
)
tsl_time_summary(tsl_15_days)[
c(
"units",
"resolution_min",
"resolution_max"
)
]
if(interactive()){
tsl_plot(tsl_15_days)
}
#aligning two time series listsç
#two time series lists with different time ranges
tsl1 <- tsl_simulate(
n = 2,
rows = 80,
time_range = c("2010-01-01", "2020-01-01"),
irregular = TRUE
)
tsl2 <- tsl_simulate(
n = 2,
rows = 120,
time_range = c("2005-01-01", "2024-01-01"),
irregular = TRUE
)
#check time features
tsl_time_summary(tsl1)[
c(
"begin",
"end",
"resolution_min",
"resolution_max"
)
]
tsl_time_summary(tsl2)[
c(
"begin",
"end",
"resolution_min",
"resolution_max"
)
]
#tsl1 to regular
tsl1_regular <- tsl_resample(
tsl = tsl1
)
#tsl2 resampled to time of tsl1_regular
tsl2_regular <- tsl_resample(
tsl = tsl2,
new_time = tsl1_regular
)
#check alignment
tsl_time_summary(tsl1_regular)[
c(
"begin",
"end",
"resolution_min",
"resolution_max"
)
]
tsl_time_summary(tsl2_regular)[
c(
"begin",
"end",
"resolution_min",
"resolution_max"
)
]
Run the code above in your browser using DataLab