Created
April 17, 2018 10:58
-
-
Save jumpingrivers/a05f8ae598747be49679b0b75790f2e2 to your computer and use it in GitHub Desktop.
This file contains 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("tidyverse", lib.loc="L:/RLIB") | |
############################## | |
# 1. Read in the data | |
############################## | |
Rladies<- readLines("https://raw.githubusercontent.com/jumpingrivers/meetingsR/master/03-Rladies.Rmd") | |
Asia <-readLines("https://raw.githubusercontent.com/jumpingrivers/meetingsR/master/02_useR_groups_asia.Rmd") | |
Europe <-readLines("https://raw.githubusercontent.com/jumpingrivers/meetingsR/master/02_useR_groups_europe.Rmd") | |
MiddleEast <-readLines("https://raw.githubusercontent.com/jumpingrivers/meetingsR/master/02_useR_groups_middle_east_africa.Rmd") | |
NAmerica <- readLines("https://raw.githubusercontent.com/jumpingrivers/meetingsR/master/02_useR_groups_north_america.Rmd") | |
Oceania <- readLines("https://raw.githubusercontent.com/jumpingrivers/meetingsR/master/02_useR_groups_oceania.Rmd") | |
SAmerica <-readLines("https://raw.githubusercontent.com/jumpingrivers/meetingsR/master/02_useR_groups_south_america.Rmd") | |
############################3 | |
# 2. Function to extract data | |
############################# | |
make_table <- function(mydata, group_type){ | |
countries = vector() | |
city1 = vector() | |
city=vector() | |
link = vector() | |
type=vector() | |
marker = 0 | |
country = vector() | |
for (i in 1:length(mydata)){ | |
if (grepl('##', mydata[i])==TRUE){ | |
each_country <- gsub('##','',mydata[i]) | |
each_country <- gsub(' ', '', each_country) | |
countries= c(countries, each_country) | |
marker = marker + 1 | |
} | |
if (grepl('[*]', mydata[i])==TRUE){ | |
each_city <- gsub('[*]','',mydata[i]) | |
just_city <- unlist(strsplit(each_city, ":"))[1] | |
just_city <- gsub(' ', '', just_city) | |
just_link <-unlist(strsplit(each_city, "[(]"))[2] | |
just_link <- gsub ('[)]', '', just_link) | |
just_link <- gsub(';.*', '', just_link) | |
just_link <- gsub('[[].*', '', just_link) | |
city1 <- c(city1, each_city ) | |
city <-c(city, just_city) | |
link <- c(link, just_link) | |
country <- c(country, countries[marker]) | |
} | |
} | |
RGroup_type <- rep(group_type, length(city)) | |
final <- data.frame(city, link, country, RGroup_type, stringsAsFactors = FALSE) | |
final2 <- as.tibble(final) | |
return (final2) | |
} | |
############################# | |
# 3. Run Function on all data | |
############################# | |
Rladies_table=make_table(Rladies, "RLadies") | |
Asia_table=make_table(Asia, "Rgroup") | |
Europe_table=make_table(Europe, "Rgroup") | |
MiddleEast_table=make_table(MiddleEast, "Rgroup") | |
NAmerica_table=make_table(NAmerica, "Rgroup") | |
Oceania_table=make_table(Oceania, "Rgroup") | |
SAmerica_table=make_table(SAmerica, "Rgroup") | |
############################### | |
# 4. Create Table of all Groups | |
############################### | |
RGroups <- full_join(Rladies_table, Asia_table) %>% | |
full_join(Europe_table) %>% | |
full_join(MiddleEast_table) %>% | |
full_join(NAmerica_table) %>% | |
full_join(Oceania_table) %>% | |
full_join(SAmerica_table) | |
################### | |
# 5. Save as a CSV | |
################### | |
write.csv(RGroups, "RGroups.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment