0

I want to create a table out of this twitteR output. Here is my code:

datafile <- read.csv(file="~Path/Workbook.csv")

data <-data.frame(lapply(datafile$recordName,as.character),stringsAsFactors = F)

x <- lapply(data[1:30], function(x) searchTwitter(x,n=5,since="2016-01-01"))

write.csv(x, file = "x.csv")

I am getting the following error:

Error in as.data.frame.default(x[[i]], optional = TRUE) : 
cannot coerce class "structure("status", package = "twitteR")" to a data.frame

I think I understand what is happening. Rows in the datafiles$recordName are producing different numbers of "searchTwitter" results (e.g., some record names show up more often on Twitter than others). What I would like to see in my CSV is a table with a column with all of the records and repeating if necessary. I'm not sure how to achieve that.

I'm not sure if this is possible and anything will help. I'd be nice to be able to export this information as a clean table.

Here is a reproducible example:

R file:

library(twitteR)
consumer_key <- " "
consumer_secret <- " "
access_token <- " "
access_secret <- " "
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)

datafile <- read.csv(file="/path/Workbook4.csv")
data <- data.frame(datafile$recordName, stringsAsFactors = F)
data <-data.frame(lapply(datafile$recordName,as.character),stringsAsFactors = F)
datafile

x <- lapply(data[1:4], function(x) searchTwitter(x,n=5,since="2016-01-01"))

x

write.csv(x, file = "x.csv")

Workbook4.csv

recordName,info
Spiderman 2,movie
Dodgers,mlb
blahblaheoi,random
Trump,pol
hy9fesh
  • 589
  • 2
  • 15
  • Please provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). It would help to see the contents of the CSV file or the `data` data frame. – neilfws Oct 16 '17 at 04:04
  • Hi @neilfws, I added the CSV file and the .R file to my original post. – hy9fesh Oct 16 '17 at 05:00

0 Answers0