Hey,
I am tryint to do webmining with corpus, dplyr, tidytext etc. and I got this code:
install.packages("NLP")
install.packages("magrittr")
install.packages("dplyr")
install.packages("tm")
install.packages("dplyr") # alternative installation of the %>%
install.packages("tidytext")
install.packages("corpus")
install.packages("tidyverse")
install.packages("installr")
library(tm)
library(tm.plugin.webmining)
library(purrr)
library(magrittr) # want to use %>%
library(dplyr) ## für mutate
library("xml2")
library(rvest)
library(xml2)
library(tidyselect)
library(tidyr)
library(corpus)
library(tm)
library(tm.plugin.webmining)
library(rJava)
library(RCurl)
library(tidyverse)
library(installr)
company <- c("Microsoft", "Apple", "Google")
symbol <- c("MSFT", "AAPL", "GOOG")
download_articles <- function(symbol) {
WebCorpus(YahooNewsSource(paste0("NASDAQ:", symbol)))
}
download_articles
stock_articles <- data_frame(company = company,
symbol = symbol) %>%
mutate(corpus = map(symbol, download_articles))
stock_articles
turn each into a dataframe using tidy(), then tokenize the text using unnest_tokens
library(tidytext)
stock_tokens <- stock_articles %>%
mutate(corpus = map(corpus, tidy)) %>%
unnest(cols = (corpus)) %>%
unnest_tokens(word, text) %>%
select(company, datetimestamp, word, id, heading)
stock_tokens
After running, I always got this error-code:
Error: Must extract column with a single valid subscript.
x Subscript var
has the wrong type function
.
i It must be numeric or character.
I am getting it after unning this section above:
turn each into a dataframe using tidy(), then tokenize the text using unnest_tokens
library(tidytext)
stock_tokens <- stock_articles %>%
mutate(corpus = map(corpus, tidy)) %>%
unnest(cols = (corpus)) %>%
unnest_tokens(word, text) %>%
select(company, datetimestamp, word, id, heading)
stock_tokens
Does anyone knows how I can fix it?
Thanks for every advice
Greeting,
Morphi