Extract Characters from a String in R



We can use stri_sub function in stringi package.

Example

> x<- "TutorialsPoint is the largest online library for best tutorials"
> x
[1] "TutorialsPoint is the largest online library for best tutorials"
> library(stringi)
> stri_sub(x,1,9)
[1] "Tutorials"
> stri_sub(x,1,-20)
[1] "TutorialsPoint is the largest online library"
> stri_sub(x,-14,-1)
[1] "best tutorials"
> stri_sub(x,-41,-1)
[1] "largest online library for best tutorials"
Updated on: 2020-07-06T14:29:06+05:30

651 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements