Input the world-happiness-report.csv and world-happiness-report-2021.csv files
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.1.1 v dplyr 1.0.6
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
happy <- read_csv("world-happiness-report.csv")
##
## -- Column specification --------------------------------------------------------
## cols(
## Country_name = col_character(),
## year = col_double(),
## Life_Ladder = col_double(),
## Log_GDP_per_capita = col_double(),
## Social_support = col_double(),
## Healthy_life_expectancy_at_birth = col_double(),
## Freedom_to_make_life_choices = col_double(),
## Generosity = col_double(),
## Perceptions_of_corruption = col_double(),
## Positive_affect = col_double(),
## Negative_affect = col_double()
## )
happy <- read_csv(file.choose())
##
## -- Column specification --------------------------------------------------------
## cols(
## Country_name = col_character(),
## year = col_double(),
## Life_Ladder = col_double(),
## Log_GDP_per_capita = col_double(),
## Social_support = col_double(),
## Healthy_life_expectancy_at_birth = col_double(),
## Freedom_to_make_life_choices = col_double(),
## Generosity = col_double(),
## Perceptions_of_corruption = col_double(),
## Positive_affect = col_double(),
## Negative_affect = col_double()
## )
happy21 <- read_csv("world-happiness-report-2021.csv")
##
## -- Column specification --------------------------------------------------------
## cols(
## .default = col_double(),
## Country_name = col_character(),
## Regional_indicator = col_character()
## )
## i Use `spec()` for the full column specifications.
happy21 <- read_csv(file.choose())
##
## -- Column specification --------------------------------------------------------
## cols(
## .default = col_double(),
## Country_name = col_character(),
## Regional_indicator = col_character()
## )
## i Use `spec()` for the full column specifications.
head(happy)
## # A tibble: 6 x 11
## Country_name year Life_Ladder Log_GDP_per_capita Social_support
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Afghanistan 2008 3.72 7.37 0.451
## 2 Afghanistan 2009 4.40 7.54 0.552
## 3 Afghanistan 2010 4.76 7.65 0.539
## 4 Afghanistan 2011 3.83 7.62 0.521
## 5 Afghanistan 2012 3.78 7.70 0.521
## 6 Afghanistan 2013 3.57 7.72 0.484
## # ... with 6 more variables: Healthy_life_expectancy_at_birth <dbl>,
## # Freedom_to_make_life_choices <dbl>, Generosity <dbl>,
## # Perceptions_of_corruption <dbl>, Positive_affect <dbl>,
## # Negative_affect <dbl>
names(happy)
## [1] "Country_name" "year"
## [3] "Life_Ladder" "Log_GDP_per_capita"
## [5] "Social_support" "Healthy_life_expectancy_at_birth"
## [7] "Freedom_to_make_life_choices" "Generosity"
## [9] "Perceptions_of_corruption" "Positive_affect"
## [11] "Negative_affect"
head(happy21)
## # A tibble: 6 x 20
## Country_name Regional_indicat~ Ladder_score Standard_error_of_la~ upperwhisker
## <chr> <chr> <dbl> <dbl> <dbl>
## 1 Finland Western Europe 7.84 0.032 7.90
## 2 Denmark Western Europe 7.62 0.035 7.69
## 3 Switzerland Western Europe 7.57 0.036 7.64
## 4 Iceland Western Europe 7.55 0.059 7.67
## 5 Netherlands Western Europe 7.46 0.027 7.52
## 6 Norway Western Europe 7.39 0.035 7.46
## # ... with 15 more variables: lowerwhisker <dbl>, Logged_GDP_per_capita <dbl>,
## # Social_support <dbl>, Healthy_life_expectancy <dbl>,
## # Freedom_to_make_life_choices <dbl>, Generosity <dbl>,
## # Perceptions_of_corruption <dbl>, Ladder_score_in_Dystopia <dbl>,
## # Explained by_Log_GDP_per_capita <dbl>, Explained by_Social_support <dbl>,
## # Explained by_Healthy_life_expectancy <dbl>,
## # Explained_by_Freedom_to_make_life_choices <dbl>,
## # Explained_by_Generosity <dbl>,
## # Explained_by_Perceptions_of_corruption <dbl>, Dystopia_residual <dbl>
names(happy21)
## [1] "Country_name"
## [2] "Regional_indicator"
## [3] "Ladder_score"
## [4] "Standard_error_of_ladder_score"
## [5] "upperwhisker"
## [6] "lowerwhisker"
## [7] "Logged_GDP_per_capita"
## [8] "Social_support"
## [9] "Healthy_life_expectancy"
## [10] "Freedom_to_make_life_choices"
## [11] "Generosity"
## [12] "Perceptions_of_corruption"
## [13] "Ladder_score_in_Dystopia"
## [14] "Explained by_Log_GDP_per_capita"
## [15] "Explained by_Social_support"
## [16] "Explained by_Healthy_life_expectancy"
## [17] "Explained_by_Freedom_to_make_life_choices"
## [18] "Explained_by_Generosity"
## [19] "Explained_by_Perceptions_of_corruption"
## [20] "Dystopia_residual"
one table
happy21 %>%
count(Healthy_life_expectancy > 70, sort = TRUE)
## # A tibble: 2 x 2
## `Healthy_life_expectancy > 70` n
## <lgl> <int>
## 1 FALSE 115
## 2 TRUE 34