library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
library(readr)
library(ggplot2)
life_expectancy<-read_csv("life expectancy.csv")
## Rows: 265 Columns: 69
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Country Name, Country Code, Indicator Name, Indicator Code
## dbl (65): 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, ...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
life_2024 <- life_expectancy %>%
select(`Country Name`, `Country Code`, `2024`) %>%
rename(life_expectancy = `2024`) %>%
filter(!is.na(life_expectancy))
life_2024 %>% summarize(n_countries = n(),mean_life_expectancy = mean(life_expectancy))
## # A tibble: 1 × 2
## n_countries mean_life_expectancy
## <int> <dbl>
## 1 264 73.7
life_2024 %>%
count(above_avg = life_expectancy > mean(life_expectancy))
## # A tibble: 2 × 2
## above_avg n
## <lgl> <int>
## 1 FALSE 124
## 2 TRUE 140
life_2024 <- life_2024 %>%
mutate(above_avg = if_else(life_expectancy > mean(life_expectancy),
"Above average", "At or below average"))
ggplot(life_2024, aes(x = above_avg)) +
geom_bar(fill = "darkgreen") +
labs(title = "Countries Above vs. At-or-Below Average Life Expectancy (2024)",
x = "Group",
y = "Number of Countries")
Publish your R Markdown document to RPub’s (https://rpubs.com/) and share your link in this discussion form (Title your post the name with the question you used to guide your exploration)