Removes leading and trailing spaces and tabs from a string.
USAGE:
strip.blanks(str)
REQUIRED ARGUMENTS:
str
a character vector containing leading and trailing spaces and tabs to strip.
If
str is not of class "character" it is coerced to
character and then the spaces and tabs are stripped.
If
str is a recursive object, leading and trailing spaces and tabs are
removed from each component using
sapply.
VALUE:
if
str is an atomic object,
a character object like
str
with any leading or trailing spaces and tabs removed.
Spaces and tabs internal to the string are not affected.
If
str is a recursive, the return value is
the results of using
sapply to apply the function to
each component.
SEE ALSO:
,
,
,
.
EXAMPLES:
# make a character vector:
cvec <- c(" a", " a ", " a", " b", "b ", "c d")
# remove the leading and trailing spaces:
strip.blanks(cvec)
# results should be [1] "a" "a" "a" "b" "b" "c d"
# a factor with leading and trailing spaces in the levels:
fvec <- factor(cvec)
fvec
levels(fvec)
# results should be [1] " a" " a" " a " " b" "b " "c d"
# a character vector with no leading and trailing spaces:
strip.blanks(fvec)
# a factor with no leading and trailing spaces in the levels:
fvec <- factor(strip.blanks(fvec))
levels(fvec)
# results should be [1] "a" "b" "c d"