Learn R Programming

arkhe (version 0.5.0)

replace: Data Replacement

Description

Replaces missing or infinite values or zeros.

Usage

replace_NA(x, ...)

replace_Inf(x, ...)

replace_zero(x, ...)

# S4 method for matrix replace_NA(x, value = 0)

# S4 method for matrix replace_Inf(x, value = 0)

# S4 method for matrix replace_zero(x, value)

Arguments

x

A matrix, a data.frame or a *Matrix object.

...

Currently not used.

value

A possible value to replace missing or infinite values of x.

Author

N. Frerebeau

See Also

Other data cleaning tools: assign(), count(), detect(), remove()

Examples

Run this code
## Create a count data matrix
X <- matrix(sample(1:10, 25, TRUE), nrow = 5, ncol = 5)

## Add NA
k <- sample(1:25, 3, FALSE)
X[k] <- NA
X

## Count missing values in rows
count(X, f = is.na, margin = 1)
## Count non-missing values in columns
count(X, f = is.na, margin = 2, negate = TRUE)

## Find row with NA
detect(X, f = is.na, margin = 1)
## Find column without any NA
detect(X, f = is.na, margin = 2, negate = TRUE, all = TRUE)

## Remove row with any NA
compact(X, f = is.na, margin = 1, all = FALSE)
## Remove column with any NA
compact(X, f = is.na, margin = 2, all = FALSE)

## Replace NA with zeros
replace_NA(X, value = 0)

Run the code above in your browser using DataLab