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

replace_NA(x, ...)

remove_NA(x, ...)

remove_empty(x, ...)

remove_zero(x, ...)

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

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

# 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.

value

A possible value to replace missing values of x.

margin

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

finite

A logical scalar: should non-finite values also be removed?

Author

N. Frerebeau

Examples

## Create a count data matrix A <- CountMatrix(sample(1:10, 25, TRUE), nrow = 5, ncol = 5) A[sample(1:25, 3, FALSE)] <- 0L # Add zeros A
#> <CountMatrix: 5 x 5> #> col1 col2 col3 col4 col5 #> row1 10 5 2 1 8 #> row2 4 7 9 10 7 #> row3 8 0 1 2 0 #> row4 7 1 8 4 5 #> row5 7 5 3 10 0
## Remove row with zeros remove_zero(A, margin = 1)
#> Removed 2 rows (zeros): #> * row3 (2) #> * row5 (1)
#> <CountMatrix: 3 x 5> #> col1 col2 col3 col4 col5 #> row1 10 5 2 1 8 #> row2 4 7 9 10 7 #> row4 7 1 8 4 5
## Remove column with zeros remove_zero(A, margin = 2)
#> Removed 2 columns (zeros): #> * col2 (1) #> * col5 (2)
#> <CountMatrix: 5 x 3> #> col1 col3 col4 #> row1 10 2 1 #> row2 4 9 10 #> row3 8 1 2 #> row4 7 8 4 #> row5 7 3 10