A simple look into tidygapminder

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

This package aims to make really easy to tidy data retrieved from Gapminder. A the beginning is:

library(tidygapminder)

When you have loaded the package you are now in possession of two super powers (functions): tidy_indice and tidy_bunch.

tidy_indice

tidy_indice function tidy as explain above tidy a data sheet downloaded on Gapminder. This data sheet can be either in csv or xlsx as indicated on the gapminder site.

tidy_indice take as argument the path to the file and return the data as a tidy data frame.

filepath <- system.file("extdata", "life_expectancy_years.csv", package = "tidygapminder")

# From .............................
df <- data.table::fread(filepath)

head(df)

# To................................

ti_df <- tidy_indice(filepath)

head(ti_df)

tidy_bunch

tidy_bunch makes use of tidy_indice to tidy a whole set of data sheets and have the options to merge all data frames into one big data frame with merge set to TRUE:

dir_path <- system.file("extdata", package = "tidygapminder")

# From ................................
list.files(dir_path)

# To ..................................
td_dp <- tidy_bunch(dir_path, merge = TRUE)

head(td_dp)

Enjoy!!!



Try the tidygapminder package in your browser

Any scripts or data that you put into this service are public.

tidygapminder documentation built on Feb. 4, 2020, 9:08 a.m.