如何在 R 中從字串中提取字元?


我們可以在 stringi 包中使用 stri_sub 函式。

示例

> 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"

更新於: 2020 年 7 月 6 日

623 次瀏覽

開始您的職業生涯

完成教程並獲得認證

開始
廣告
© . All rights reserved.