Wednesday, 29 July 2015

R : substr : Returns sub string

“substr()” is used to extract or replace substrings in a character vector.

Usage
substr(x, start, stop)
substr(x, start, stop) <- value
> x <- "Hello How are you"
> 
> substr(x, 7, 9)
[1] "How"
> 
> substr(x, 7, 9) <- "who"
> x
[1] "Hello who are you"

substr(x, 7, 9) <- “who”
Above statement replace “how” by “who”.


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment