我有一个文本数据框,如下所示。
> 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
我想将此文本数据合并到一个单元格中(进行情感分析),如下所示
> gettext.df
gettext
1 hello, Good to hear back from you. I've currently written an application and I'm happy about it
所以我使用下面的代码
折叠了单元格paste(gettext.df, collapse =" ")
但似乎它将这些文本数据组成一个块(作为一个单词),因此我无法逐字扫描该句子。
有没有什么方法可以将这些句子合并为一个句子集合,而不会变成一个大字块?
答案 0 :(得分:12)
在使用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"