Learn R Programming

ahw (version 0.1.0)

naReplace: Replaces NA-values in vec with last non-NA value

Description

Assumes first element is non-NA

Usage

naReplace(vec)

Value

numeric

vector with each NA entry replaced with the last previous non-NA entry.

Arguments

vec

Vector of any type

Author

Pål Christie Ryalen <p.c.ryalen@medisin.uio.no>

Examples

Run this code
naReplace(c(1, 2, 3, NA, NA, 4))
naReplace(c("text", NA, NA))

Run the code above in your browser using DataLab