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
matrixor 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(25, 3, FALSE)
X[k] <- ""
X
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] "J" "B" "U" "D" "M"
#> [2,] "S" "" "T" "A" "H"
#> [3,] "B" "" "A" "Q" ""
#> [4,] "D" "Z" "Q" "B" "L"
#> [5,] "L" "G" "F" "V" "A"
## Remove rows with empty strings
remove_empty(X, margin = 1)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] "J" "B" "U" "D" "M"
#> [2,] "D" "Z" "Q" "B" "L"
#> [3,] "L" "G" "F" "V" "A"
## Replace empty strings
replace_empty(X, value = "XXX")
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] "J" "B" "U" "D" "M"
#> [2,] "S" "XXX" "T" "A" "H"
#> [3,] "B" "XXX" "A" "Q" "XXX"
#> [4,] "D" "Z" "Q" "B" "L"
#> [5,] "L" "G" "F" "V" "A"
