uts_data_check_and_fill_w_na: Check monthly long format data for gaps and fill with NAs if...

Description Usage Arguments Details Value Examples

Description

Time series objects don't allow missing years or months. Check and fill missing data with NAs w/ {tsibble} functions and provide output as tsibble with generated Year_Month as time index.

Usage

1

Arguments

data

A data frame with monthly "count" in long format and separate columns "Year" and "Month"

key

Variable(s) that uniquely determine time indices. NULL (dafault) for empty key. Required, if multiple time indices exist (e.g. key = "Measure" if Temperature and Precipitation data exist)

Details

Time series objects don't allow gaps in time (missing years or months). With tsibble functions check and fill gaps in time and add NA count values and provide output in wide Month format (Year Temp_Precip Jan Feb .... Dec)

data input format (Month in long format)
Year Month Temp_Precip count
<dbl> <dbl> <chr> <dbl>
1 1887 1 Temperature NA
2 1887 1 Precipitation 4
3 1887 2 Temperature NA
:
5 2019 12 Temperature 4.55
6 2019 12 Precipitation 30.4

data output format (Month in wide format)
Year Temp_Precip Jan Feb ... Dec
<dbl> <fct> <dbl> <dbl> ... <dbl>
1 1887 Temperature NA NA ... NA
:
3 1889 Temperature -3.1 -2.09 ...-1.01

Value

data frame and tsibble, e.g.:
A tsibble: 754 x 4
Year_Month Year Month count
<mth> <dbl> <fct> <dbl>

Examples

1
2
3
4
5
6
7
8
data <- monthly_climate_basel %>%
  dplyr::select(City, Measure, Year, Month, count)
uts_data_check_and_fill_w_na(data, key = "Measure")

# delete all "2017" and "Feb" rows and fill with NAs
data <- monthly_climate_basel %>%
  dplyr::filter(Year != 2017 & Month != "Feb")
uts_data_check_and_fill_w_na(data, key = "Measure")

WoVollmer/pkgTS documentation built on June 2, 2021, 4:02 a.m.