Replaces empty strings.
Usage
replace_empty(x, ...)
# S4 method for class 'matrix'
replace_empty(x, value)
# S4 method for class 'data.frame'
replace_empty(x, value)
Arguments
- x
An R object (should be a
matrix
or adata.frame
).- ...
Currently not used.
- value
A possible replacement value.
See also
Other data cleaning tools:
clean_whitespace()
,
remove_Inf()
,
remove_NA()
,
remove_constant()
,
remove_empty()
,
remove_zero()
,
replace_Inf()
,
replace_NA()
,
replace_zero()
Examples
## Create a data matrix
X <- matrix(sample(LETTERS, 25, TRUE), nrow = 5, ncol = 5)
## Add empty string
k <- sample(1:25, 3, FALSE)
X[k] <- ""
X
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] "O" "D" "D" "Z" "Q"
#> [2,] "" "G" "L" "G" ""
#> [3,] "C" "J" "" "U" "D"
#> [4,] "I" "S" "Z" "T" "A"
#> [5,] "N" "B" "B" "A" "Q"
## Remove rows with empty strings
remove_empty(X, margin = 1)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] "O" "D" "D" "Z" "Q"
#> [2,] "I" "S" "Z" "T" "A"
#> [3,] "N" "B" "B" "A" "Q"
## Replace empty strings
replace_empty(X, value = "XXX")
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] "O" "D" "D" "Z" "Q"
#> [2,] "XXX" "G" "L" "G" "XXX"
#> [3,] "C" "J" "XXX" "U" "D"
#> [4,] "I" "S" "Z" "T" "A"
#> [5,] "N" "B" "B" "A" "Q"