fill_by_function: Fill missing values by a function of the nonmissings

View source: R/fill_functions.R

fill_by_functionR Documentation

Fill missing values by a function of the nonmissings

Description

For each specified column in x replace the missing values by a function of the nonmissing values.

Usage

fill_by_function(x, ..., fun = mean)

Arguments

x

A data frame.

...

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

fun

The function to apply on the nonmissing values.

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)
x_df %>% pad %>% fill_by_function(y1, y2)
x_df %>% pad %>% fill_by_function(y1, y2, fun = median)

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