I'm cleaning up some data and found that the person who entered the data made some mistakes and entered duplicate rows, except for one column. In that column, I need to add the two numbers together and then remove the duplicate rows. My data set is over 1 million rows, so I've provided a fictitious example. I'm still assessing, but it looks like I have about 300 instances of this.
Example
data <- data.frame(City = c("Portland", "Portland", "Seattle", "Seattle", "Los Angeles", "Las Vegas", "Salt Lake City"),
Country = c("USA", "USA", "USA", "USA", "USA", "USA", "USA"),
Year = c("2020", "2020", "2020", "2020", "2020", "2020", "2020"),
Population = c(25, 5, 30, 8, 10, 15, 15))
Expected
expected <- data.frame(City = c("Portland", "Seattle", "Los Angeles", "Las Vegas", "Salt Lake City"),
Country = c("USA", "USA", "USA", "USA", "USA"),
Year = c("2020", "2020", "2020", "2020", "2020"),
Population = c(30, 38, 10, 15, 15))