Skip to contents

This function pad data to complete years. The fill mechanism is:

Usage

pad_to_year_fill(data, date_col, interval, ...)

Arguments

data

input data

date_col

column containing time information

interval

interval between two dates. See seq.POSIXt() for valid values

...

columns to fill up

Value

padded data

Examples

fn <- rOstluft.data::f("Zch_Stampfenbachstrasse_min30_2013_Jan.csv")
data <- rOstluft::read_airmo_csv(fn)

tail(data)
#> # A tibble: 6 × 6
#>   starttime           site                    parameter interval unit  value
#>   <dttm>              <fct>                   <fct>     <fct>    <fct> <dbl>
#> 1 2013-01-31 21:00:00 Zch_Stampfenbachstrasse WVv       min30    m/s    5.96
#> 2 2013-01-31 21:30:00 Zch_Stampfenbachstrasse WVv       min30    m/s    6.00
#> 3 2013-01-31 22:00:00 Zch_Stampfenbachstrasse WVv       min30    m/s    6.75
#> 4 2013-01-31 22:30:00 Zch_Stampfenbachstrasse WVv       min30    m/s    6.59
#> 5 2013-01-31 23:00:00 Zch_Stampfenbachstrasse WVv       min30    m/s    5.28
#> 6 2013-01-31 23:30:00 Zch_Stampfenbachstrasse WVv       min30    m/s    3.68

# fills up all factor and character columns
pad_to_year_fill(data, starttime, "30 min") %>% tail()
#> # A tibble: 6 × 6
#>   starttime           site                    parameter interval unit  value
#>   <dttm>              <fct>                   <fct>     <fct>    <fct> <dbl>
#> 1 2013-12-31 21:00:00 Zch_Stampfenbachstrasse WVv       min30    m/s      NA
#> 2 2013-12-31 21:30:00 Zch_Stampfenbachstrasse WVv       min30    m/s      NA
#> 3 2013-12-31 22:00:00 Zch_Stampfenbachstrasse WVv       min30    m/s      NA
#> 4 2013-12-31 22:30:00 Zch_Stampfenbachstrasse WVv       min30    m/s      NA
#> 5 2013-12-31 23:00:00 Zch_Stampfenbachstrasse WVv       min30    m/s      NA
#> 6 2013-12-31 23:30:00 Zch_Stampfenbachstrasse WVv       min30    m/s      NA

# or only the specific and the rest with na
pad_to_year_fill(data, starttime, "30 min", site) %>% tail()
#> # A tibble: 6 × 6
#>   starttime           site                    parameter interval unit  value
#>   <dttm>              <fct>                   <fct>     <fct>    <fct> <dbl>
#> 1 2013-12-31 21:00:00 Zch_Stampfenbachstrasse NA        NA       NA       NA
#> 2 2013-12-31 21:30:00 Zch_Stampfenbachstrasse NA        NA       NA       NA
#> 3 2013-12-31 22:00:00 Zch_Stampfenbachstrasse NA        NA       NA       NA
#> 4 2013-12-31 22:30:00 Zch_Stampfenbachstrasse NA        NA       NA       NA
#> 5 2013-12-31 23:00:00 Zch_Stampfenbachstrasse NA        NA       NA       NA
#> 6 2013-12-31 23:30:00 Zch_Stampfenbachstrasse NA        NA       NA       NA

# data in wide format
data <- rOstluft::rolf_to_openair(data)
pad_to_year_fill(data, date, "30 min") %>% tail()
#> # A tibble: 6 × 16
#>   date                site          CO    Hr    NO   NO2   NOx    O3     p  PM10
#>   <dttm>              <fct>      <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 2013-12-31 21:00:00 Zch_Stamp…    NA    NA    NA    NA    NA    NA    NA    NA
#> 2 2013-12-31 21:30:00 Zch_Stamp…    NA    NA    NA    NA    NA    NA    NA    NA
#> 3 2013-12-31 22:00:00 Zch_Stamp…    NA    NA    NA    NA    NA    NA    NA    NA
#> 4 2013-12-31 22:30:00 Zch_Stamp…    NA    NA    NA    NA    NA    NA    NA    NA
#> 5 2013-12-31 23:00:00 Zch_Stamp…    NA    NA    NA    NA    NA    NA    NA    NA
#> 6 2013-12-31 23:30:00 Zch_Stamp…    NA    NA    NA    NA    NA    NA    NA    NA
#> # ℹ 6 more variables: RainDur <dbl>, SO2 <dbl>, StrGlo <dbl>, T <dbl>,
#> #   wd <dbl>, ws <dbl>

# but be careful not to include cutting factors
data <- openair::cutData(data, "month") %>%
  dplyr::select(month, dplyr::everything())

# fills up month and would multiply the data by the numbers of months
pad_to_year_fill(data, date, "30 min") %>% tail()
#> # A tibble: 6 × 17
#>   month  date                site         CO    Hr    NO   NO2   NOx    O3     p
#>   <ord>  <dttm>              <fct>     <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Januar 2013-12-31 21:00:00 Zch_Stam…    NA    NA    NA    NA    NA    NA    NA
#> 2 Januar 2013-12-31 21:30:00 Zch_Stam…    NA    NA    NA    NA    NA    NA    NA
#> 3 Januar 2013-12-31 22:00:00 Zch_Stam…    NA    NA    NA    NA    NA    NA    NA
#> 4 Januar 2013-12-31 22:30:00 Zch_Stam…    NA    NA    NA    NA    NA    NA    NA
#> 5 Januar 2013-12-31 23:00:00 Zch_Stam…    NA    NA    NA    NA    NA    NA    NA
#> 6 Januar 2013-12-31 23:30:00 Zch_Stam…    NA    NA    NA    NA    NA    NA    NA
#> # ℹ 7 more variables: PM10 <dbl>, RainDur <dbl>, SO2 <dbl>, StrGlo <dbl>,
#> #   T <dbl>, wd <dbl>, ws <dbl>

# only fills up the site column
pad_to_year_fill(data, date, "30 min", site) %>% tail()
#> # A tibble: 6 × 17
#>   month date                site          CO    Hr    NO   NO2   NOx    O3     p
#>   <ord> <dttm>              <fct>      <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 NA    2013-12-31 21:00:00 Zch_Stamp…    NA    NA    NA    NA    NA    NA    NA
#> 2 NA    2013-12-31 21:30:00 Zch_Stamp…    NA    NA    NA    NA    NA    NA    NA
#> 3 NA    2013-12-31 22:00:00 Zch_Stamp…    NA    NA    NA    NA    NA    NA    NA
#> 4 NA    2013-12-31 22:30:00 Zch_Stamp…    NA    NA    NA    NA    NA    NA    NA
#> 5 NA    2013-12-31 23:00:00 Zch_Stamp…    NA    NA    NA    NA    NA    NA    NA
#> 6 NA    2013-12-31 23:30:00 Zch_Stamp…    NA    NA    NA    NA    NA    NA    NA
#> # ℹ 7 more variables: PM10 <dbl>, RainDur <dbl>, SO2 <dbl>, StrGlo <dbl>,
#> #   T <dbl>, wd <dbl>, ws <dbl>