Hello, i have a question about gapminder

Hello , i'm studying gapminder now.
In the middle of studying, i really don't know how to solve the problem.
My friend said i have to use gather in this problem.
Problem is i have to find the all the years that africa continent population>europe continent population
But i really don't know how to adapt gather to this problem.
Help me guys!
Thanks!!

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)

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.