Last active
January 27, 2021 22:33
-
-
Save luisDVA/635ae12054fa36eb93d2407471eb4e64 to your computer and use it in GitHub Desktop.
Compound values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## %######################################################%## | |
# # | |
#### 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 | |
# Optional: Arrange the data by ISO3 country code | |
# load packages ----------------------------------------------------------- | |
library(readr) | |
library(dplyr) | |
library(tidyr) | |
library(unheadr) | |
library(janitor) | |
library(stringr) | |
# import data ------------------------------------------------------------- | |
MPAs <- read_csv("data/MPAS-your.csv") %>% | |
mash_colnames(1) %>% | |
clean_names() | |
# separate columns -------------------------------------------------------- | |
# separate the country codes variable (ISO3 and UN scheme) | |
MPAs <- MPAs %>% separate( | |
col = country_code_iso_un, | |
into = c("country_code_ISO3", "country_code_UN"), | |
sep = " " | |
) # two spaces | |
# separate rows ------------------------------------------------------------- | |
# separate the 'reference' variable | |
MPAs <- MPAs %>% | |
separate_rows(reference, sep = "\\|") | |
# arrange by ISO3 country codes --------------------------------------------- | |
MPAs <- MPAs %>% arrange(country_code_ISO3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment