Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R, merge multiple rows of text data frame into one cell

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?

like image 295
user1486507 Avatar asked Dec 31 '13 08:12

user1486507


1 Answers

You have to transform the data frame column into a character vector before using paste.

paste(unlist(gettext.df), collapse =" ")

This returns:

[1] "hello, Good to hear back from you. I've currently written an application and I'm happy about it"
like image 114
Sven Hohenstein Avatar answered Oct 10 '22 16:10

Sven Hohenstein