0

I have a table in which there are 30 columns. One column is country names and other the dates which have number of recovered patients from corona. there is repetition in country names and every time they have different values . now i want to add all the values for a date for the same country.

for example

china 0 9  3
china 1 3  4
china 3 1  5

enter image description here output should be:

china 4 13 12

PS: I have different functions like rowSums, across(everything()) by grouping against country.region but could not able to solve. Any help would be much appreciated

Aksen P
  • 4,564
  • 3
  • 14
  • 27
  • Please run `dput()` on your data and copy the result into your question. Also add the code you have tried. This will make answering your question easier. Thanks – L Tyrone Apr 08 '23 at 04:27
  • Base R: `aggregate(. ~ ctry, dat, FUN = sum)`; dplyr `group_by(dat, ctry) %>% summarize(across(everything(), ~ sum(.)))`; data.table `as.data.table(dat)[, lapply(.SD, sum), by = .(ctry)]`. If none of those work in your case, then please [edit] your question, add content that clearly shows why/how they get it wrong, then @-ping me and we'll try to resolve it. – r2evans Apr 08 '23 at 04:30

0 Answers0