fill_by_prevalent: Fill missing values by the most prevalent nonmissing value

View source: R/fill_functions.R

fill_by_prevalentR Documentation

Fill missing values by the most prevalent nonmissing value

Description

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

Usage

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)

padr documentation built on Nov. 23, 2022, 5:06 p.m.