Replaces missing or infinite values or zeros.

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.

See also

Other utilities: remove()

Author

N. Frerebeau

Examples

## Create a count data matrix
X <- CountMatrix(sample(1:10, 25, TRUE), nrow = 5, ncol = 5)
k <- sample(1:25, 3, FALSE)

## Add zeros
X[k] <- 0L
## Remove row with zeros
remove_zero(X, margin = 1)
#> 2 rows were removed:
#> * row1 (n=1)
#> * row5 (n=2)
#> <CountMatrix: 3 x 5>
#>      col1 col2 col3 col4 col5
#> row2    2    3    9    5    7
#> row3    2    5    4    7   10
#> row4    5    2    4    5   10
## Remove column with zeros
remove_zero(X, margin = 2)
#> 2 columns were removed:
#> * col3 (n=1)
#> * col4 (n=2)
#> <CountMatrix: 5 x 3>
#>      col1 col2 col5
#> row1    8   10    6
#> row2    2    3    7
#> row3    2    5   10
#> row4    5    2   10
#> row5    5    4    3

## Add NA
X[k] <- NA
## Remove row with zeros
remove_NA(X, margin = 1)
#> 2 rows were removed:
#> * row1 (n=1)
#> * row5 (n=2)
#> <CountMatrix: 3 x 5>
#>      col1 col2 col3 col4 col5
#> row2    2    3    9    5    7
#> row3    2    5    4    7   10
#> row4    5    2    4    5   10
## Remove column with zeros
remove_NA(X, margin = 2)
#> 2 columns were removed:
#> * col3 (n=1)
#> * col4 (n=2)
#> <CountMatrix: 5 x 3>
#>      col1 col2 col5
#> row1    8   10    6
#> row2    2    3    7
#> row3    2    5   10
#> row4    5    2   10
#> row5    5    4    3