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
## %######################################################%##
# #
#### Unusable variable names - your turn ####
# #
## %######################################################%##
# - Import the Marine Protected Areas data (MPAS-your.csv)
# - Make the variable names usable by placing all header fragments in a single
# header row
# - Clean the names for consistency
## %######################################################%##
# #
#### Whitespace - your turn ####
# #
## %######################################################%##
# - Import the Marine Protected Areas data (MPAS-your.csv) from the previous lesson
# - check the Country variable for leading or trailing whitespace
# - Remove it if necessary.
## %######################################################%##
# #
#### Letter case - your turn ####
# #
## %######################################################%##
# Import the Marine Protected Areas dataset (MPAS-your.csv)
# Summarize the number of Marine Protected Areas by country (Country full).
@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_"
## %######################################################%##
# #
#### Compound values - your turn ####
# #
## %######################################################%##
# Import the Marine Protected Areas dataset (MPAS-your.csv)
# Separate the country codes variable (ISO3 and UN scheme)
# Unnest the Reference variable
# > Keep an eye on the separators
## %######################################################%##
# #
#### 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
## %######################################################%##
# #
#### Broken values - your turn ####
# #
## %######################################################%##
# Load the raw Age of Empires units dataset from csv (aoe_raw.csv)
# Identify the broken values in both the 'Type' and 'Name' columns and unbreak them
# Clean up any separator-related issues arising from the 'unbreaking'