library(tidyverse)
library(gapminder)
gapminder %>%
filter(continent %in% c("Africa", "Europe")) %>%
group_by(year, continent) %>%
summarise(population = sum(pop)) %>%
spread(continent, population) %>%
filter(Africa > Europe)
#> # A tibble: 5 x 3
#> # Groups: year [5]
#> year Africa Europe
#> <int> <int> <int>
#> 1 1987 574834110 543094160
#> 2 1992 659081517 558142797
#> 3 1997 743832984 568944148
#> 4 2002 833723916 578223869
#> 5 2007 929539692 586098529
Created on 2019-12-03 by the reprex package (v0.3.0)