1

Hello everybody in Stackoverflow. I am a newbie R user, and having problem with lapply function.

Now I am using R version 3.0.1 (2013-05-16) -- "Good Sport" running on Ubuntu server 12.04.2 LTS.

My problem is I can't use lapply function to convert the output from searchTwitter (in twitteR) to data frame.

I can gather the tweet into 'tweet' variable, but can't convert to the data frame.

My code:

require(twitteR) 
require(RJSONIO)
load('cred.Rdata')
registerTwitterOAuth(cred)
tweet <- searchTwitter('bus')
tweet1 <- lapply(tweet, as.data.frame) //error here
df <- do.call("rbind",tweet1)
write.csv(df,file='oneearthquake.csv')

I got the error:

Error in data.frame(text= "(tweet text)")
    arguments imply differing number of rows: 1,0

I have tried on another Ubuntu server which running the same R version, it can run with out any warning. Could please tell me the way to solve this error?

Thank you in advance

Ploy

  • Have you tried [`twListToDF`](http://www.inside-r.org/packages/cran/twitteR/docs/twListToDF) or the answers [here](http://stackoverflow.com/q/3056146/1036500)? They may be a bit dated though... – Ben Jun 30 '13 at 16:48
  • I tried and the error was the same. – user2536641 Jul 01 '13 at 03:29

1 Answers1

2

Try something like this

load('cred.Rdata')
registerTwitterOAuth(cred)
rawtweets <- searchTwitter("bus")

df <- do.call("rbind", lapply(rawtweets, as.data.frame))
write.csv(df, file='oneearthquake.csv')
dickoa
  • 18,217
  • 3
  • 36
  • 50