Answers for "r last element of string"

0

r last element of string

x <- "some text in a string"

substrRight <- function(x, n){
  substr(x, nchar(x)-n+1, nchar(x))
}

substrRight(x, 6)
[1] "string"

substrRight(x, 8)
[1] "a string"
Posted by: Guest on June-28-2020

Code answers related to "r last element of string"

Browse Popular Code Answers by Language