I have this vector:
x <- c("a", " b", "c", "d", " e", "f")
There are spaces in x[c(2,5)]
How to delete the spaces to get all elements without spaces?, like this:
x <- c("a", "b", "c", "d", "e", "f")
Thanks
You can use a gsub
:
gsub(" ", "", x)
Note that this approach will remove any spaces in the elements of x, not only those at the beginning or end of each element.