This dataframe:
data.frame(
stringsAsFactors = FALSE,
check.names = FALSE,
unic = c("ARG","BAL",
"BEM","BEN","BER","CAB","CAC",
"CAM","CAR","DON"),
`2022` = c(1, 1, 4, 1, 0, 1, 1, 5, 4, 0),
`2021` = c(1, 0, 7, 0, 0, 4, 1, 3, 4, 2),
`2020` = c(1, 0, 12, 0, 1, 4, 1, 8, 5, 0),
`2019` = c(0, 0, 12, 0, 0, 5, 3, 4, 4, 4),
`2018` = c(0, 0, 10, 1, 1, 0, 6, 6, 1, 0),
`2017` = c(0, 0, 8, 1, 0, 1, 6, 8, 1, 1),
`2016` = c(1, 0, 4, 0, 0, 1, 10, 1, 5, 1),
`2015` = c(1, 1, 7, 2, 0, 1, 1, 8, 0, 0)
)
I want to get the three 'munic' with more total ocurrences and group the remaining in an new row called 'Others'. In this example something similar to:
munic 2022 2021 2020 2019 2018 2017 2016 2015
BEM 4 7 12 12 10 8 4 7
CAC 1 1 1 3 6 6 10 1
CAM 5 3 8 4 6 8 1 8
Others 7 10 10 13 3 4 7 4
Any idea?