Removes empty rows/columns in an array-like object using a predicate function.
Usage
compact(x, ...)
compact_cols(x, ...)
compact_rows(x, ...)
# S4 method for ANY
compact(x, margin = 1)
# S4 method for ANY
compact_cols(x)
# S4 method for ANY
compact_rows(x)
Arguments
- x
An R object (should be a
matrix
or adata.frame
).- ...
Currently not used.
- margin
A length-one
numeric
vector giving the subscripts which the function will be applied over (1
indicates rows,2
indicates columns).
Details
A row/column is empty if it contains only NA
, zeros (if of type numeric
)
or zero length character strings (if of type character
).
See also
remove_NA()
, remove_zero()
, remove_empty()
Other data cleaning tools:
count()
,
detect()
,
discard()
,
empty
,
infinite
,
keep()
,
missing
,
remove_constant()
,
zero
Examples
## Create a data.frame
X <- data.frame(A = 0, B = 1:5, C = 6, D = "", F = letters[1:5])
X
#> A B C D F
#> 1 0 1 6 a
#> 2 0 2 6 b
#> 3 0 3 6 c
#> 4 0 4 6 d
#> 5 0 5 6 e
## Remove empty columns
compact(X, margin = 2)
#> B C F
#> 1 1 6 a
#> 2 2 6 b
#> 3 3 6 c
#> 4 4 6 d
#> 5 5 6 e