R,将多行文本数据框架合并到一个单元格中 [英] R, merge multiple rows of text data frame into one cell

查看:477
本文介绍了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"

这篇关于R,将多行文本数据框架合并到一个单元格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆