Skip to contents

Remove rows and columns containing only NA values

Usage

removeNa(object, ...)

# S4 method for DFrame
removeNa(object)

# S4 method for Matrix
removeNa(object)

# S4 method for atomic
removeNa(object)

# S4 method for data.frame
removeNa(object)

# S4 method for matrix
removeNa(object)

Arguments

object

Object.

...

Additional arguments.

Value

Sanitized object.

Note

Updated 2021-10-14.

Examples

## atomic ====
removeNa(c("hello", "world", NA))
#> [1] "hello" "world"
#> attr(,"na.action")
#> [1] 3
#> attr(,"class")
#> [1] "omit"
removeNa(c(1, 2, NA))
#> [1] 1 2
#> attr(,"na.action")
#> [1] 3
#> attr(,"class")
#> [1] "omit"

## matrix ====
from <- matrix(
    data = c(1, NA, 3, NA, NA, NA, 2, NA, 4),
    nrow = 3,
    ncol = 3
)
print(from)
#>      [,1] [,2] [,3]
#> [1,]    1   NA    2
#> [2,]   NA   NA   NA
#> [3,]    3   NA    4
to <- removeNa(from)
print(to)
#>      [,1] [,2]
#> [1,]    1    2
#> [2,]    3    4

## DFrame ====
from <- S4Vectors::DataFrame(
    "a" = c("A", NA, "C"),
    "b" = c(NA, NA, NA),
    "c" = c("B", NA, "D")
)
print(from)
#> DataFrame with 3 rows and 3 columns
#>             a         b           c
#>   <character> <logical> <character>
#> 1           A        NA           B
#> 2          NA        NA          NA
#> 3           C        NA           D
to <- removeNa(from)
print(to)
#> DataFrame with 2 rows and 2 columns
#>             a           c
#>   <character> <character>
#> 1           A           B
#> 2           C           D