Skip to content

Instantly share code, notes, and snippets.

@mrchypark
Created November 3, 2018 18:59
Show Gist options
  • Save mrchypark/daaa1848a4c10e24061ddae8eea314a2 to your computer and use it in GitHub Desktop.
Save mrchypark/daaa1848a4c10e24061ddae8eea314a2 to your computer and use it in GitHub Desktop.
library(purrr)
library(readr)
library(httr)
library(rvest)
library(dplyr)
"https://github.com/FinanceData/marcap/tree/master/data" %>%
GET() %>%
content() %>%
html_nodes("td.content span a") %>%
html_text -> tar_list
tar_list %>%
map(~ download.file(
paste0("https://github.com/FinanceData/marcap/raw/master/data/",.x),
paste0("./data-raw/",.x)))
tar_list %>%
paste0("./data-raw/", .) -> tt
tt %>%
map_dfr(~ read_csv(.x) %>%
mutate(MarcapRatio = ifelse(is.character(MarcapRatio), as.numeric(MarcapRatio),MarcapRatio)) %>%
mutate(ForeignShares = ifelse(is.character(ForeignShares), as.numeric(ForeignShares),ForeignShares)) %>%
mutate(ForeignRatio = ifelse(is.character(ForeignRatio), as.numeric(ForeignRatio),ForeignRatio))
) -> marcap
use_data(marcap)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment