Skip to content

Instantly share code, notes, and snippets.

View luisDVA's full-sized avatar

Luis Verde Arregoitia luisDVA

View GitHub Profile
library(ggplot2)
library(dplyr)
# datos internos que vienen con ggplot2
animals <-
msleep %>% slice_max(sleep_rem, n = 30) %>% # seleccionando top 30
ggplot(aes(x = forcats::fct_reorder(name, sleep_total), y = sleep_total, label = name)) +
geom_bar(stat = "identity") + xlab("") +
geom_text(nudge_y = 2, hjust = 0) +
theme(
@luisDVA
luisDVA / regex-01_understanding-regex.R
Last active November 24, 2020 20:07
Understanding a regular expression - your turn: Solutions
## %######################################################%##
# #
#### Understanding a regular expression - your turn ####
# #
## %######################################################%##
# Write regular expressions to match:
# Test with stringr, regexplain, or a web-based regex tester
# "cute, cuuute, cuuuuuute, and cuuuuuuuuute"
@luisDVA
luisDVA / regex-02_regex-4-data-cleaning.R
Created November 24, 2020 20:54
Regex for data cleaning
## %######################################################%##
# #
#### Regex for data cleaning - your turn ####
# #
## %######################################################%##
# 1. Download CRAN package descriptions
# 2. Select Package name, author, description, and all variables that end in 'ports'
# 3. Filter rows for packages with names that:
# - end in plot
@luisDVA
luisDVA / common-issues-04_emb-subheaders.R
Created November 25, 2020 20:10
Missing, implicit, or misplaced grouping variables
## %######################################################%##
# #
#### Missing, implicit, or misplaced ####
#### grouping variables - your turn ####
# #
## %######################################################%##
# Load the `primates2017` dataset bundled with 📦 `unheadr`
# Create a new column that groups the different species by taxonomic family.
# In biology, taxonomic families all end in the suffix "_DAE_"
## %######################################################%##
# #
#### Duplicates - your turn ####
# #
## %######################################################%##
# Load the messy Age of Empires units dataset bundled with `unheadr` (AOEunits_raw)
# Keep only units of Type "Cavalry"
# Identify duplicated records across all variables
# Remove duplicated records across all variables
## %######################################################%##
# #
#### Useful dplyr functions - your turn ####
# #
## %######################################################%##
# Load the mammal sleep data bundled with ggplot2
# Select "name" and "conservation" columns and those that include the string 'sleep' in their name
# Create a new column that contains the values of 'sleep_total' multiplied by 3
@luisDVA
luisDVA / restructuring-02_dplyr-across.R
Created January 2, 2021 02:40
Working with columns using across
## %######################################################%##
# #
#### Working with columns with 'across' - Your Turn ####
# #
## %######################################################%##
# Load the midwest data bundled with ggplot2
# Keep only rows for Ohio (OH)
# Subset the 'county' column and all columns that match the string 'pop' (hint: use a selection helper)
# Square-root transform all numeric variables
@luisDVA
luisDVA / restructuring-04_coalesce-and-fill.R
Last active January 12, 2021 22:36
Coalesce and Fill
## %######################################################%##
# #
#### Coalesce and Fill - Your Turn ####
# #
## %######################################################%##
# Load the fish landings data 'fish-landings.csv'
# Fill the 'Fish' and 'Lake' columns
# Reorder the numeric variables ('Comission reported total' first)
# create a new column, coalescing the three numeric variables
@luisDVA
luisDVA / restructuring-03_pivoting.R
Last active January 12, 2021 22:36
Pivoting Data
## %######################################################%##
# #
#### Pivoting Data - Your Turn ####
# #
## %######################################################%##
# Load the dog ranks data ("dogranks_your.csv")
# Pivot the data (wide to long and back to wide)
# load packages -----------------------------------------------------------
@luisDVA
luisDVA / common-issues-10_aoe-demo.R
Last active January 12, 2021 22:37
Putting everything together
## %######################################################%##
# #
#### Putting everything together ####
#### Chained data cleaning demonstration ####
# #
## %######################################################%##
# Load the raw Age of Empires units dataset from csv (aoe_raw.csv)
# Identify and fix common issues that make these data unusable