Remove Leading/Trailing Whitespace
Arguments
- x
An R object (should be a
matrixor adata.frame).- ...
Currently not used.
- which
A
characterstring specifying whether to removebothleading and trailing whitespace (default), or only leading ("left") or trailing ("right").- squish
A
logicalscalar: should all internal whitespace be replaced with a single space?
See also
Other data cleaning tools:
remove_Inf(),
remove_NA(),
remove_constant(),
remove_empty(),
remove_zero(),
replace_Inf(),
replace_NA(),
replace_empty(),
replace_zero()
Examples
x <- data.frame(
A = c(" Both ", " Left", "Right "),
B = 1:3
)
clean_whitespace(x, which = "both")
#> A B
#> 1 Both 1
#> 2 Left 2
#> 3 Right 3
clean_whitespace(x, which = "left")
#> A B
#> 1 Both 1
#> 2 Left 2
#> 3 Right 3
clean_whitespace(x, which = "right")
#> A B
#> 1 Both 1
#> 2 Left 2
#> 3 Right 3
