0

I have a dataframe that looks like this:

> head(df)
  Gene                                         Region
1 ANKS1B                      Brain...Hypothalamus
2 ANKS1B                          Brain...Amygdala
5 AXE2 Brain...Nucleus.accumbens..basal.ganglia.
6 AXE2           Brain...Putamen..basal.ganglia.

I want to turn it into this

> head(df)
  Gene                                               Region
1 ANKS1B              Brain...Hypothalamus, Brain...Amygdala
5 AXE2                Brain...Nucleus.accumbens..basal.ganglia., Brain...Putamen..basal.ganglia.

Essentially, I want to collapse rows in which the gene value is the same, and append the Region, separated by a ",". How can I do this? My dataframe is ~50,000 rows.

Workhorse
  • 1,500
  • 1
  • 17
  • 27

0 Answers0