I have this dataframe here of the countries in the world:
structure(list(long = c(290.100891113281, 290.104309082031, 290.057800292969,
289.995849609375, 289.933868408203, 289.949127197266, 289.964874267578,
290.02685546875, 290.088195800781, 290.100891113281, 74.8913116455078,
74.8402328491211, 74.7673797607422, 74.7389602661133, 74.7266616821289,
74.6689453125, 74.5589904785156, 74.3721694946289, 74.3761672973633,
74.4979553222656), lat = c(12.4520015716553, 12.4229984283447,
12.4385251998901, 12.50048828125, 12.5469722747803, 12.5970697402954,
12.6141109466553, 12.567626953125, 12.48046875, 12.4520015716553,
37.2316398620605, 37.2250518798828, 37.2491722106934, 37.28564453125,
37.2907218933105, 37.2667007446289, 37.2366218566895, 37.15771484375,
37.1373519897461, 37.0572242736816), group = c(1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), order = c(1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L), region = c("Aruba", "Aruba", "Aruba", "Aruba",
"Aruba", "Aruba", "Aruba", "Aruba", "Aruba", "Aruba", "Afghanistan",
"Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan",
"Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan"),
subregion = c(NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_), population = c(71891L, 71891L, 71891L, 71891L,
71891L, 71891L, 71891L, 71891L, 71891L, 71891L, 31056997L,
31056997L, 31056997L, 31056997L, 31056997L, 31056997L, 31056997L,
31056997L, 31056997L, 31056997L)), .Names = c("long", "lat",
"group", "order", "region", "subregion", "population"), row.names = c(1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 12L, 13L, 14L, 15L, 16L,
17L, 18L, 19L, 20L, 21L), class = "data.frame")
In the rest of the dataframe, there are some countries with NA population values. I would like a way to insert the population values for these countries with NA population values.
For example, I want to put int the population values for USA
world %>%
filter(region == "USA") %>%
mutate(population = 298444215)
This makes a separate dataframe with only the data for USA. However, I would ideally like to mutate the population values only for USA inside the entire dataframe that I dputted above!