Replace all missing values in the specified columns by the same value.

fill_by_value(x, ..., value = 0)

Arguments

x

A data frame.

...

The unquoted column names of the variables that should be filled.

value

The value to replace the missing values by.

Value

x with the altered columns.

Examples

library(dplyr) # for the pipe operator x <- seq(as.Date('2016-01-01'), by = 'day', length.out = 366) x <- x[sample(1:366, 200)] %>% sort x_df <- data_frame(x = x, y1 = runif(200, 10, 20) %>% round, y2 = runif(200, 1, 50) %>% round, y3 = runif(200, 20, 40) %>% round, y4 = sample(letters[1:5], 200, replace = TRUE)) x_padded <- x_df %>% pad
#> pad applied on the interval: day
x_padded %>% fill_by_value(y1)
#> # A tibble: 365 x 5 #> x y1 y2 y3 y4 #> <date> <dbl> <dbl> <dbl> <chr> #> 1 2016-01-01 19 4 22 d #> 2 2016-01-02 0 NA NA NA #> 3 2016-01-03 0 NA NA NA #> 4 2016-01-04 0 NA NA NA #> 5 2016-01-05 0 NA NA NA #> 6 2016-01-06 13 50 25 d #> 7 2016-01-07 19 22 25 d #> 8 2016-01-08 0 NA NA NA #> 9 2016-01-09 18 29 21 b #> 10 2016-01-10 15 41 24 c #> # … with 355 more rows
x_df %>% pad %>% fill_by_value(y1, y2, value = 42)
#> pad applied on the interval: day
#> # A tibble: 365 x 5 #> x y1 y2 y3 y4 #> <date> <dbl> <dbl> <dbl> <chr> #> 1 2016-01-01 19 4 22 d #> 2 2016-01-02 42 42 NA NA #> 3 2016-01-03 42 42 NA NA #> 4 2016-01-04 42 42 NA NA #> 5 2016-01-05 42 42 NA NA #> 6 2016-01-06 13 50 25 d #> 7 2016-01-07 19 22 25 d #> 8 2016-01-08 42 42 NA NA #> 9 2016-01-09 18 29 21 b #> 10 2016-01-10 15 41 24 c #> # … with 355 more rows