Skip to content

Instantly share code, notes, and snippets.

@luisDVA
Last active January 12, 2021 22:38
Show Gist options
  • Save luisDVA/613c405c42f3d1d910108e1235db91d9 to your computer and use it in GitHub Desktop.
Save luisDVA/613c405c42f3d1d910108e1235db91d9 to your computer and use it in GitHub Desktop.
Broken values
## %######################################################%##
# #
#### 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'
# load packages -----------------------------------------------------------
library(dplyr)
library(unheadr)
library(readr)
library(stringr)
# load data ---------------------------------------------------------------
aoe_raw <- read_csv("data/aoe_raw.csv")
# unbreak -----------------------------------------------------------------
aoe_ub <- aoe_raw %>%
unbreak_vals("^\\(", ogcol = Name, newcol = Name_ub) %>% # trailing half of broken values
unbreak_rows("-$", ogcol = Type) # leading half
# cleanup -----------------------------------------------------------------
aoe_ub <- aoe_ub %>% mutate(Type = str_replace(
string = Type,
pattern = "- ",
replacement = " "
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment