Last active
August 29, 2015 14:18
-
-
Save jlehtoma/6c2c7748c78682fc97c1 to your computer and use it in GitHub Desktop.
Join and update transect
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
library(dplyr) | |
library(magrittr) | |
museum_transects <- read.table("data/museon_linjat.csv", as.is = TRUE, | |
sep = ";", header = TRUE) | |
standard_transects <- read.table("data/vakioreitit_lista_suojelualueet.csv", | |
as.is = TRUE, sep = ";", header = TRUE) | |
# Select only columns Reitti and Suojelualue form standard_transects | |
standard_transects %<>% select(Reitti, Suojelualue) | |
lsa_transects <- museum_transects %>% | |
# Calculate new column `Reitti` | |
mutate(Reitti = Nro.2 - 8000) %>% | |
# Join the data frame in process (".") with standard_transect using Reitti | |
# as key | |
left_join(., standard_transects, by="Reitti") %>% | |
# Update the values for LSA (when non-empty) with those from Suojelualue when | |
# Suojelualue is non-empty | |
mutate(LSA = ifelse(LSA != "", LSA, ifelse(!is.na(Suojelualue), | |
Suojelualue, ""))) %>% | |
# Finally, remove columns Reitti and Suojelualue from the data frame in | |
# process to retain the column structure of the original data | |
# (museum_transects) | |
select(-Reitti, -Suojelualue) | |
# Replace "0" with "%" and "1" with "+" in LSA | |
lsa_transects$LSA[lsa_transects$LSA == "0"] <- "%" | |
lsa_transects$LSA[lsa_transects$LSA == "1"] <- "+" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment