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(devtools) | |
library(twitteR) | |
api_key <- "89a1epAjv6QL2drupmbkYDAXX" | |
api_secret <- "pYBHCKVWKNsuq4stoVM3HF2KBAmcCsgcLPvnY7SwyUuWBxAWfH" | |
access_token <- "2352914730-1Dx4Xel5WTHBZuXuLv8AEBKXkgEgSdRzFlG0jPp" | |
access_token_secret <- "mMLw1ryN9D2W5wurR2b68JGNvLv69zLp0xx7V6gXJedW6" |
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
require(devtools) | |
install_url("http://cran.r-project.org/src/contrib/Archive/sentiment/sentiment_0.2.tar.gz") | |
require(sentiment) | |
ls("package:sentiment") |
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(twitteR) | |
library(ROAuth) | |
library(ggplot2) | |
kejriwal.list <- searchTwitter('#kejriwal', n=1000) | |
#twListToDF() will take a list of objects from a single twitteR class and return a data.frame version of the members | |
kejriwal.df =twListToDF(kejriwal.list) | |
write.csv(kejriwal.df, file='c:/test/kejriwal.csv', row.names=F) |
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(XML) | |
library(RCurl) | |
library(tm) | |
library(tmcn) | |
library(Rwordseg) | |
setwd("C:/test") | |
d.corpus <-Corpus(DirSource("/test/doc"), readerControl = list(language="UTF-8")) | |
#上兩行為抓取本機文字檔, 餘皆同網路上說明文字 |
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
policy.HTML.page <-readLines("http://policy.unt.edu/policy/3-5") | |
length(policy.HTML.page) | |
policy.HTML.page[186:202] | |
id.1 <- 3 + which(policy.HTML.page ==" TOTAL UNIVERSITY </div>") | |
id.2 <- id.1+5 | |
text.data <- policy.HTML.page[id.1:id.2] | |
rm(policy.HTML.page, id.1, id.2) | |
text.data |
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(tm) | |
setwd('C:/test/001') | |
#sets R's working directory to near where my files are | |
a <-Corpus(DirSource("/001"), readerControl = list(language="lat")) | |
summary(a) | |
a <- tm_map(a, removeNumbers) | |
a <- tm_map(a , stripWhitespace) | |
a <- tm_map(a, removePunctuation) |
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(RTextTools) | |
library(tm) | |
#讀取資料 | |
data(NYTimes) | |
data <- NYTimes[sample(1:3100, size=100, replace=FALSE),] | |
#建立 文本-詞語 矩陣 | |
matrix <- create_matrix(cbind(data["Title"],data["Subject"]), language = "english", removeNumbers = TRUE, stemWords = FALSE, weighting = weightTfIdf) |