【问题标题】:r - convert the searchTwitter output to data frame? [duplicate]r - 将 searchTwitter 输出转换为数据框? [复制]
【发布时间】:2013-06-27 20:13:31
【问题描述】:

大家好 Stackoverflow。 我是 R 新手,遇到 lapply 功能问题。

现在我使用的是 R 版本 3.0.1 (2013-05-16) -- “Good Sport” 在 Ubuntu 服务器 12.04.2 LTS 上运行。

我的问题是我无法使用 lapply 函数将 searchTwitter(在 twitteR 中)的输出转换为数据框。

我可以将推文收集到“推文”变量中,但无法转换为数据框。

我的代码:

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')

我得到了错误:

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

我在另一台运行相同 R 版本的 Ubuntu 服务器上进行了尝试,它可以在没有任何警告的情况下运行。能告诉我解决这个错误的方法吗?

提前谢谢你

谋略

【问题讨论】:

  • 你试过twListToDF或答案here吗?它们可能有点过时了......
  • 我试过了,还是一样。

标签: r list twitter dataframe lapply


【解决方案1】:

试试这样的

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

df <- do.call("rbind", lapply(rawtweets, as.data.frame))
write.csv(df, file='oneearthquake.csv')

【讨论】:

  • 感谢您的建议。我试过了,但错误是一样的。
  • 这对我有用
猜你喜欢
  • 1970-01-01
  • 2022-01-23
  • 2019-08-31
  • 2017-10-19
  • 2020-08-07
  • 1970-01-01
  • 2018-08-02
  • 2018-09-01
相关资源
最近更新 更多