-1

enter image description hereI have a dataframe that has several rows with the same ID and columns 1 to 1273 (please see image). I would like to merge all the rows with the same ID.

I tried this R code (attached image - I can't seem to add my code in text)enter image description here:

This did not exactly work for me because I was expecting to see the attached imageenter image description here. Could I please get some assistance with this, I would greatly appreciate it.

SetshabaT
  • 1
  • 1
  • 1
    *"I can't seem to add my code in text"*. Why not? Just copy&paste, then [format as code](https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks). Made very simple [here](https://meta.stackexchange.com/a/193324/388946) – Rui Barradas Nov 17 '22 at 06:55
  • 1
    Greetings! Usually it is helpful to provide a minimally reproducible dataset for questions here so people can troubleshoot your problems (rather than a table or screenshot for example). One way of doing is by using the `dput` function on the data or a subset of the data you are using, then pasting the output into your question. You can find out how to use it here: https://youtu.be/3EID3P1oisg – Shawn Hemelstrand Nov 17 '22 at 09:08
  • Does this answer your question? [R: Combine rows with same ID](https://stackoverflow.com/questions/72853248/r-combine-rows-with-same-id) – pimaniye41 Dec 13 '22 at 08:11

1 Answers1

0

This should work for you. df %>% group_by(sample)%>% summarise(across(starts_with("a"), ~sum(., na.rm = T)))

taken from this post: R: Combine rows with same ID

pimaniye41
  • 79
  • 9