Calculate the continental average for each numeric data column:
header <- c("Life Expectancy", "Population", "GDP per Capita")
temp <- data.frame()
for (continent in unique(gapminder$continent)) {
current <- c(
mean(gapminder[gapminder$continent==continent,]$lifeExp,
na.rm = TRUE),
mean(gapminder[gapminder$continent==continent,]$pop,
na.rm = TRUE),
mean(gapminder[gapminder$continent==continent,]$gdpPercap,
na.rm=TRUE))
temp <- rbind(temp,current)
}
names(temp) <- header
rownames(temp) <- unique(gapminder$continent)
temp
## Life Expectancy Population GDP per Capita
## Asia 60.06490 77038722 7902.150
## Europe 71.90369 17169765 14469.476
## Africa 48.86533 9916003 2193.755
## Americas 64.65874 24504795 7136.110
## Oceania 74.32621 8874672 18621.609