Skip to content

Instantly share code, notes, and snippets.

@juliasilge
Created November 8, 2017 02:55
Show Gist options
  • Save juliasilge/0012543273062c6a7674a21eeed47f39 to your computer and use it in GitHub Desktop.
Save juliasilge/0012543273062c6a7674a21eeed47f39 to your computer and use it in GitHub Desktop.
Check out whether downloading/tidying financial text data is working
library(tm.plugin.webmining)
library(tidyverse)
library(tidytext)
company <- c("Microsoft", "Apple", "Google", "Amazon", "Facebook",
"Twitter", "IBM", "Yahoo", "Netflix")
symbol <- c("MSFT", "AAPL", "GOOG", "AMZN", "FB", "TWTR", "IBM", "YHOO", "NFLX")
download_articles <- function(symbol) {
WebCorpus(GoogleFinanceSource(paste0("NASDAQ:", symbol)))
}
stock_articles <- data_frame(company = company,
symbol = symbol) %>%
mutate(corpus = map(symbol, download_articles))
stock_tokens <- stock_articles %>%
unnest(map(corpus, tidy)) %>%
unnest_tokens(word, text) %>%
select(company, datetimestamp, word, id, heading)
stock_tokens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment