Skip to content

Instantly share code, notes, and snippets.

View luisDVA's full-sized avatar

Luis Verde Arregoitia luisDVA

View GitHub Profile
@luisDVA
luisDVA / pkgcomments.R
Created April 7, 2023 17:44
Code commets about loaded packages
# exploring comments about loaded packages
library(bigrquery) # CRAN v1.4.1
library(dplyr) # CRAN v1.1.1
library(stringr) # CRAN v1.5.0
library(readr) # CRAN v2.1.4
library(tidyr) # CRAN v1.3.0
library(rlang) # CRAN v1.1.0
library(purrr) # CRAN v1.0.1
@luisDVA
luisDVA / svghelp.R
Created July 30, 2022 13:46
can't seem to change fill color in geom_point_svg
library(ggsvg)
library(ggplot2)
# the svg that I need to use
svg_url <- "https://raw.githubusercontent.com/luisDVA/luisdva.github.io/master/assets/images/Cat-green.svg"
cat_svg <- paste(readLines(svg_url), collapse = "\n")
# toy data
dat <-
expand.grid(y=1:2,x=seq_len(2))
dat$qual <- letters[1:4]
@luisDVA
luisDVA / mapluis.R
Created May 20, 2022 18:03
problema_map
# lista 1
dat1a <- tibble(id=c("A","B","C","D","E"),val=rnorm(5))
dat1b <- tibble(id=c("A","B","C","D","E"),val=rnorm(5))
dat1 <- list(dat1a,dat1b)
dat1
# lista dos
dat2a <- tibble(id=c("A","D","E"),label=rnorm(3))
dat2b_1 <- tibble(id=c("A","B","C","E"),label=rnorm(4))
## %######################################################%##
# #
#### Regex for data cleaning 1 - your turn ####
# #
## %######################################################%##
# After running the code below:
library(ggplot2)
library(dplyr)
##%######################################################%##
# #
#### Regex in R - Your Turn ####
# #
##%######################################################%##
# Match the following regular expressions against the test vector below using `str_detect`.
## Can you explain the matches?
@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 / 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
## %######################################################%##
# #
#### 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 / 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