Created
October 22, 2021 10:13
-
-
Save geotheory/181074295369fcea891c55798396d913 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# identify and fill missing data points in timeseries data with regular-periodicity | |
require(padr) | |
#> Loading required package: padr | |
df <- data.frame(date = as.Date('2016-04-01') + 3*c(0,1,3,5,6), val = sample(5)) |> | |
print() | |
#> date val | |
#> 1 2016-04-01 3 | |
#> 2 2016-04-04 1 | |
#> 3 2016-04-10 2 | |
#> 4 2016-04-16 4 | |
#> 5 2016-04-19 5 | |
pad(df, interval = '3 days') |> print() |> | |
fill_by_value(val, value = 0) |> print() | |
#> date val | |
#> 1 2016-04-01 3 | |
#> 2 2016-04-04 1 | |
#> 3 2016-04-07 NA | |
#> 4 2016-04-10 2 | |
#> 5 2016-04-13 NA | |
#> 6 2016-04-16 4 | |
#> 7 2016-04-19 5 | |
#> date val | |
#> 1 2016-04-01 3 | |
#> 2 2016-04-04 1 | |
#> 3 2016-04-07 0 | |
#> 4 2016-04-10 2 | |
#> 5 2016-04-13 0 | |
#> 6 2016-04-16 4 | |
#> 7 2016-04-19 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment