-1

I have a dataframe with two columns (username and tweet). username has multiple repeating values and tweet contains different tweets that the user have posted. For example:

username   tweet
user_a     This is first tweet.
user_a     This is second tweet.
user_b     It is a good weather today.
user_b     It will rain.

For all the tweets that each user have posted, I want them to be in a single row. For example, the above dataframe should look something like this:

username   tweet
user_a     This is first tweet. This is second tweet.
user_b     It is a good weather today. It will rain.

Any guidance on how to do that please?

AneesBaqir
  • 423
  • 1
  • 12

1 Answers1

1

You can use aggregate like this:

aggregate(tweetsData, tweet ~ username , paste, collapse=" ")

  username                                      tweet
1   user_a This is first tweet. This is second tweet.
2   user_b  It is a good weather today. It will rain.
George Savva
  • 4,152
  • 1
  • 7
  • 21