我正在构建一个NLP模型来预测R中的下一个单词。所以,对于3个句子语料库:
a<-"i like cheese"
b<-"the dog like cat"
c<-"the cat eat cheese"
我希望它成为:
>a
"<.s> i like cheese <./s>"
>b
"<.s> the dog like cat <./s>"
>c
"<.s> the cat eat cheese <./s>"
有没有比这更简单的方法:
a<-Unlist(strsplit(a, " "))
a[1]<-"<.s>"
a[length(a)]<-"./s>"
a<-paste(a, collapse = " ")
> a
"<.s> i like cheese <./s>"
答案 0 :(得分:0)
您只是连接字符串,所以这应该可以工作:
a <- paste("<.s>", a, "<./s>")