Learn R Programming

imputeTS (version 2.7)

na.replace: Replace Missing Values by a Defined Value

Description

Replaces all missing values with a given value.

Usage

na.replace(x, fill = 0)

Arguments

x

Numeric Vector (vector) or Time Series (ts) object in which missing values shall be replaced

fill

Value used to replace the missing values

Value

Vector (vector) or Time Series (ts) object (dependent on given input at parameter x)

See Also

na.interpolation, na.kalman, na.locf, na.ma, na.mean, na.random, na.seadec, na.seasplit

Examples

Run this code
# NOT RUN {
#Prerequisite: Create Time series with missing values
x <- ts(c(2,3,NA,5,6,NA,7,8))

#Example 1: Replace all NAs with 3.5
na.replace(x, fill = 3.5 )

#Example 2: Replace all NAs with 0
na.replace(x, fill = 0 ) 

#Example 3: Same as example 1, just written with pipe operator
x %>% na.replace(fill = 3.5 )

# }

Run the code above in your browser using DataLab