将文本拆分为不同的部分并为每个部分指定名称

时间:2017-03-19 19:04:20

标签: r string vector tokenize

我想将以下歌曲分成单词'和' (大写或小写)并为每个拆分部分指定其名称(" V1"," V2"," V3"," V4)

因此我输入" V1" R会告诉我"它的小蜘蛛爬上了喷水口下来的雨"

这是我到目前为止所能做的:

song<-paste("The itsy-bitsy spider Climbed up the water spout Down came the rain And washed the spider out Out came the sun And dried up all the rain And the itsy-bitsy spider Climbed up tspout again")

song<-casefold(song, upper=FALSE)

strsplit(song, "and")

V1<-"the itsy-bitsy spider climbed up the water spout down came the rain "

V2<-" washed the spider out out came the sun "

V3<-" dried up all the rain "

V4<-" the itsy-bitsy spider climbed up the spout again"

然后我在R中键入V4,它给我以前删除的文本。

因此,当我在R中键入V3时,它会为我提供之前删除的文本:

  

V3   [1]&#34;干了所有的雨&#34;

我只是不想手动为每个剪辑片段指定名称,因为我正在处理的真实文本非常庞大而且无法做到。我想知道是否有可能在R?谢谢:))

0 个答案:

没有答案