substr()
function extract or replace substrings in a character vector.
substr(x, start, stop) substring(text, first, last = 1000000L) substr(x, start, stop) <- value substring(text, first, last = 1000000L) <- value
x,text
: character vector
start, first
: integer, the first element to be replaced
stop, last
: integer, the last element to be replaced
value
: character vector, recycled if necessary
> substr("tutorial",2,3)
[1] "ut"
> x <- c("green","red","blue") > substr(x,2,3)
[1] "re" "ed" "lu"
> substring(x,2,3)
[1] "re" "ed" "lu"