I am using my python script and Tweepy to collect tweets and extract only text portion. I saved all the texts from these tweets in txt format.
I am now trying to load this text in R for textual analysis using this module ( http://rpubs.com/gogamza/ko_text_mining ) However, this R module only accepts .Rdata files, and I somehow need to feed my tweet collection onto R.
The R code says:
library(twitteR)
# n <- 200
#
# keyword <- '삼성전자'
#
# keyword <- enc2utf8(keyword)
#
# rdmTweets <- searchTwitter(keyword, n)
load(url("http://dl.dropbox.com/u/8686172/twitter.RData"))
nDocs <- length(rdmTweets)
So, inside the load command, I'd like to add my own text file there.
Can someone offer me a tip? Thanks a lot.. I'd appreciate it so much.
You can load the data in your txt file in R and save it as an RData file:
sapply(list.files("/folderWithFiles", pattern="*.txt", full.names = TRUE),
function(x) { myDataInVector = scan(x, what=character()); save(myDataInVector, file=gsub("\\.txt","\\.RData",x)) } )
The reading in part scan(x, what=character())
assumes you have your data in all in the text file as a space delimited vector. You can use read.table or change the arguments of the scan command if it is in a different format.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.