Removes empty row/column or row/column with missing/ infinite values or zeros.

remove_NA(x, ...)

remove_Inf(x, ...)

remove_empty(x, ...)

remove_zero(x, ...)

# S4 method for matrix
remove_NA(x, margin = 1)

# S4 method for matrix
remove_Inf(x, margin = 1)

# S4 method for matrix
remove_zero(x, margin = 1)

# S4 method for matrix
remove_empty(x, margin = 1)

Arguments

x

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

...

Currently not used.

margin

An integer giving the subscript which the cleaning will be applied over (1 indicates rows, 2 indicates columns).

See also

Other utilities: replace()

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

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