如何从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"
以上是 如何从R中的字符串向量中提取单词? 的全部内容, 来源链接: utcz.com/z/354109.html