如何从R中的字符串向量中提取单词?
要从字符串向量中提取单词,我们可以使用stringr包的word函数。例如,如果我们有一个名为x的向量,其中包含100个单词,则可以使用命令word(x,start=1,end=20,sep=fixed(“”))提取前20个单词。如果我们想从其他任何一个字开始,则起始值将相应地更改。
示例
x<-c("R is a programming language and software environment for statistical analysis, graphics representation and reporting. R was created by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand, and is currently developed by the R Development Core Team. R is freely available under the GNU General Public License, and pre-compiled binary versions are provided for various operating systems like Linux, Windows and Mac. This programming language was named R, based on the first letter of first name of the two R authors (Robert Gentleman and Ross Ihaka), and partly a play on the name of the Bell Labs Language S.")
x输出结果[1] "R is a programming language and software environment for statistical analysis, graphics representation and reporting. R was created by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand, and is currently developed by the R Development Core Team. R is freely available under the GNU General Public License, and pre-compiled binary versions are provided for various operating systems like Linux, Windows and Mac. This programming language was named R, based on the first letter of first name of the two R authors (Robert Gentleman and Ross Ihaka), and partly a play on the name of the Bell Labs Language S."
示例
library(stringr)
word(x,start=1,end=5,sep=fixed(" "))输出结果[1] "R is a programming language"
示例
word(x,start=1,end=20,sep=fixed(" "))输出结果[1] "R is a programming language and software environment for statistical analysis, graphics representation and reporting. R was created by Ross"
示例
word(x,start=1,end=10,sep=fixed(" "))输出结果[1] "R is a programming language and software environment for statistical"
示例
word(x,start=1,end=15,sep=fixed(" "))输出结果[1] "R is a programming language and software environment for statistical analysis, graphics representation and reporting."
示例
word(x,start=1,end=50,sep=fixed(" "))输出结果[1] "R is a programming language and software environment for statistical analysis, graphics representation and reporting. R was created by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand, and is currently developed by the R Development Core Team. R is freely available under the GNU General Public"
示例
word(x,start=11,end=20,sep=fixed(" "))输出结果[1] "analysis, graphics representation and reporting. R was created by Ross"
示例
word(x,start=51,end=60,sep=fixed(" "))输出结果[1] "License, and pre-compiled binary versions are provided for various operating"
示例
word(x,start=6,end=10,sep=fixed(" "))输出结果[1] "and software environment for statistical"
示例
word(x,start=11,end=60,sep=fixed(" "))输出结果[1] "analysis, graphics representation and reporting. R was created by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand, and is currently developed by the R Development Core Team. R is freely available under the GNU General Public License, and pre-compiled binary versions are provided for various operating"
示例
word(x,start=1,end=90,sep=fixed(" "))输出结果[1] "R is a programming language and software environment for statistical analysis, graphics representation and reporting. R was created by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand, and is currently developed by the R Development Core Team. R is freely available under the GNU General Public License, and pre-compiled binary versions are provided for various operating systems like Linux, Windows and Mac. This programming language was named R, based on the first letter of first name of the two R authors (Robert Gentleman and Ross Ihaka),"
示例
word(x,start=11,end=90,sep=fixed(" "))输出结果[1] "analysis, graphics representation and reporting. R was created by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand, and is currently developed by the R Development Core Team. R is freely available under the GNU General Public License, and pre-compiled binary versions are provided for various operating systems like Linux, Windows and Mac. This programming language was named R, based on the first letter of first name of the two R authors (Robert Gentleman and Ross Ihaka),"
示例
word(x,start=21,end=90,sep=fixed(" "))输出结果[1] "Ihaka and Robert Gentleman at the University of Auckland, New Zealand, and is currently developed by the R Development Core Team. R is freely available under the GNU General Public License, and pre-compiled binary versions are provided for various operating systems like Linux, Windows and Mac. This programming language was named R, based on the first letter of first name of the two R authors (Robert Gentleman and Ross Ihaka),"
示例
word(x,start=51,end=100,sep=fixed(" "))输出结果[1] "License, and pre-compiled binary versions are provided for various operating systems like Linux, Windows and Mac. This programming language was named R, based on the first letter of first name of the two R authors (Robert Gentleman and Ross Ihaka), and partly a play on the name of the Bell"
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短