For each specified column in x replace the missing values by the most prevalent nonmissing value.

fill_by_prevalent(x, ...)

Arguments

x

A data frame.

...

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

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 = rep(letters[1:3], c(80, 70, 50)) %>% sample, y2 = rep(letters[2:5], c(60, 80, 40, 20)) %>% sample) x_df %>% pad %>% fill_by_prevalent(y1, y2)
#> pad applied on the interval: day
#> # A tibble: 366 x 3 #> x y1 y2 #> <date> <chr> <chr> #> 1 2016-01-01 a c #> 2 2016-01-02 a c #> 3 2016-01-03 a c #> 4 2016-01-04 a c #> 5 2016-01-05 a e #> 6 2016-01-06 a c #> 7 2016-01-07 b b #> 8 2016-01-08 a c #> 9 2016-01-09 a c #> 10 2016-01-10 c c #> # … with 356 more rows