Description Usage Arguments right left Examples
Vectorized wrapper for taking the left/right N characters from a string, number, factor, etc., just like in SQL. I find myself constantly trimming strings and grabbing only the first/last few characters so this saves some typing.
1 2 3 |
vec |
A vector of any datatype: |
n |
Integer scalar. The number of characters you want to keep. |
trimws |
Should the applicable leading/trailing whitespace be removed first? Default is |
sameclass |
Should the output be the same class as the input? Defaults to |
R Analog to SQL's RIGHT()
function. Defaults to trim leading whitespace.
R Analog to SQL's LEFT()
function. Defaults to trim trailing whitespace.
1 2 3 4 5 6 7 8 9 | right(vec = 'SomethingLong', n = 4)
right(vec = 425575.4, n = 5)
right(vec = 'AnotherThing ', n = 7, trimws = FALSE)
right(vec = 401.98, 4, sameclass = TRUE)
left(vec = 'SomethingLong', n = 4)
left(vec = 40000.00, n = 2)
left(vec = ' AnotherThing', n = 4, trimws = FALSE)
left(vec = 400, 1, sameclass = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.