I have this dataframe:
df <- data.frame(
stringsAsFactors = FALSE,
name = c("PA2","PA1","PA4","PA5",
"PA6","PA7","PA8","PA3","PA9","PA10","PA11"),
number = c(10417L,7436L,2552L,2660L,
2308L,2988L,2374L,198L,243L,143L,773L),
elect = c(9L, 6L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 0L, 0L)
)
I want to embrace all the "name" with 0 "elect" in a new row with the tag "Others", like Others 1357 0 (1357 is the sum of all number with elect 0) and maintain the rest of df:
name | number | elect |
---|---|---|
PA2 | 10417 | 9 |
PA1 | 7436 | 6 |
PA4 | 2552 | 2 |
PA5 | 2660 | 2 |
PA6 | 2308 | 2 |
PA7 | 2988 | 2 |
PA8 | 2374 | 2 |
Others | 1357 | 0 |
I'm try do it with forcats fct_lump, but I can't get it