Vectorized wrapper for taking the right N characters from a character, number, factor, etc. vector. Automatically trims trailing whitespace. I find myself constantly trimming strings and grabbing only the last few characters so this saves some typing.
right(vec, n, trimws = TRUE, sameclass = FALSE)
vec | A vector of any datatype. Not vectors of lists or matrices. I'm talking about |
---|---|
n | The number of characters you want to keep. |
trimws | Should the leading spaces be removed first? Default is |
sameclass | Should the output be the same class as the input? Defaults to |
right(vec = 'SomethingLong', n = 4)#> [1] "Long"right(vec = 425575.4, n = 5)#> [1] "575.4"right(vec = 'AnotherThing ', n = 7, trimws = FALSE)#> [1] "Thing "right(vec = 401.98, 4, sameclass = TRUE)#> [1] 1.98