R,将多行文本数据框架合并到一个单元格中
问题描述:
我有一个如下所示的文本数据框.
I have a text data frame that looks like below.
> nrow(gettext.df)
[1] 3
> gettext.df
gettext
1 hello,
2 Good to hear back from you.
3 I've currently written an application and I'm happy about it
我想将文本数据合并到一个单元格中(进行情感分析),如下所示
I wanted to merge this text data into one cell (to do sentiment analysis) as below
> gettext.df
gettext
1 hello, Good to hear back from you. I've currently written an application and I'm happy about it
所以我使用下面的代码折叠了单元格
so I collapsed the cell using below code
paste(gettext.df, collapse =" ")
但是似乎它将那些文本数据分成一个块(作为一个词),所以我无法逐词扫描句子.
but it seems like it makes those text data into one chunk (as one word) so I cannot scan the sentence word by word.
有什么方法可以将这些句子合并为一个句子集合,而不必转换为一个大单词块?
Is there any way that I can merge those sentence as a collection of sentences, without transforming as one big word chunk?
答
在使用paste
之前,必须将数据帧列转换为字符向量.
You have to transform the data frame column into a character vector before using paste
.
paste(unlist(gettext.df), collapse =" ")
这将返回:
[1] "hello, Good to hear back from you. I've currently written an application and I'm happy about it"