特定时间跨度内的推文 (TwitteR)

2023-12-03

有没有办法使用 twitteR 获取特定时间跨度(例如 12 月到 1 月)的推文,而不是简单地获取过去的 N 条推文(如 tweets

或者使用 TwitteR 库不可能吗? (这意味着您必须使用 Excel 之类的工具按日期对大量推文进行子集化)。


在您使用的包中,searchTwitter函数接受参数since and until,定义在文档如下:

since如果不为 NULL,则将推文限制为自给定日期以来的推文。 日期格式为 YYYY-MM-DD

until如果不为 NULL,则将推文限制为给定日期之前的推文。 日期格式为 YYYY-MM-DD

这就是你所追求的吗?或者如果您想坚持使用userTimeline函数,您可以通过操作来对所需的日期范围进行子集化created的领域status您获得的对象(因此无需使用 Excel)。

EDIT以下是您可以如何对created字段如果您正在使用userTimeline:

library(twitteR)
# get last 100 tweets from the NSF
tweets <- userTimeline('NSF', 100)
# inspect structure of first item in the status object (ie. list of results)
str(tweets[1])
List of 1
 $ :Reference class 'status' [package "twitteR"] with 10 fields
  ..$ text        : chr "From the field: Avoiding a Cartography Catastrophe:  Study recommends new tools to improve global mapping of inf... http://t.co"| __truncated__
  ..$ favorited   : logi FALSE
  ..$ replyToSN   : chr(0) 
  ..$ created     : POSIXct[1:1], format: "2013-02-05 01:43:45"
  ..$ truncated   : logi FALSE
  ..$ replyToSID  : chr(0) 
  ..$ id          : chr "298607815617036288"
  ..$ replyToUID  : chr(0) 
  ..$ statusSource: chr "<a href=\"http://twitterfeed.com\" rel=\"nofollow\">twitterfeed</a>"
  ..$ screenName  : chr "NSF"
  ..and 34 methods, of which 23 are possibly relevant:
  ..  getCreated, getFavorited, getId, getReplyToSID, getReplyToSN,
  ..  getReplyToUID, getScreenName, getStatusSource, getText,
  ..  getTruncated, initialize, setCreated, setFavorited, setId,
  ..  setReplyToSID, setReplyToSN, setReplyToUID, setScreenName,
      ..  setStatusSource, setText, setTruncated, toDataFrame, usingMethods


# convert status object to data frame for easier manipulation
tweetsdf <- twListToDF(tweets)


 # subset by `created` field, eg get all tweets between 2 Feb and 5 Feb  
    subset(tweetsdf, created >= as.POSIXct('2013-02-02 00:00:00') & created <= as.POSIXct('2013-02-05 00:00:00'))

这是该子集操作产生的数据框:

text
1   From the field: Avoiding a Cartography Catastrophe:  Study recommends new tools to improve global mapping of inf... http://t.co/F6IJ05Sb
2                  Video: Research Vessel Sikuliaq launched... and now being prepared for her first Arctic run in 2014, http://t.co/D7GlRnlm
3                                                                                        Who's watching the power grid? http://t.co/oYsgBl63
4 Ice Melt &amp; the Ice Age... research story on #AAAS #Science Update Daily, featured show @Science360 Radio, http://t.co/XRXSdYL1 #Arctic
5                                                                                             Taking LIGO to the people http://t.co/R2KHNQTB
6                            Pubs: NSF Current - January-February 2013: Available Formats: JSP: http://t.co/2NhEEj6Q... http://t.co/ZSVABpXm
7   Upcoming Due Dates: Interdisciplinary Research in Hazards and Disasters (Hazards SEES): Full Proposal Deadline D... http://t.co/IG3naAFs
8                                                     When children learn to walk, their language improves dramatically http://t.co/FGYXSKu2
  favorited replyToSN             created truncated replyToSID
1     FALSE        NA 2013-02-05 01:43:45     FALSE         NA
2     FALSE        NA 2013-02-04 19:30:40     FALSE         NA
3     FALSE        NA 2013-02-04 18:01:33     FALSE         NA
4     FALSE        NA 2013-02-04 13:55:46     FALSE         NA
5     FALSE        NA 2013-02-04 13:01:51     FALSE         NA
6     FALSE        NA 2013-02-02 17:19:30     FALSE         NA
7     FALSE        NA 2013-02-02 14:25:15     FALSE         NA
8     FALSE        NA 2013-02-02 14:02:11     FALSE         NA
                  id replyToUID
1 298607815617036288         NA
2 298513923307630592         NA
3 298491499958644736         NA
4 298429645580288000         NA
5 298416076012785666         NA
6 297756138433290240         NA
7 297712287521841156         NA
8 297706485608218624         NA
                                                     statusSource
1 <a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>
2 <a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a>
3 <a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a>
4 <a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a>
5 <a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a>
6 <a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>
7 <a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>
8 <a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a>
  screenName
1        NSF
2        NSF
3        NSF
4        NSF
5        NSF
6        NSF
7        NSF
8        NSF
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

特定时间跨度内的推文 (TwitteR) 的相关文章

  • 替换 R 中的缺失值

    我必须通过 ID 将缺失值替换为最大值 值 如何在 R 中做 ID Value 1 NA 5 15 8 16 6 8 7 65 8 NA 5 25 1 62 6 14 7 NA 9 11 8 12 9 36 1 26 4 13 我首先使用调
  • RcppArmadillo 传递用户定义函数

    考虑以下 R 代码 R version caller lt function x 1 3 fun identity do some other stuff then call the function eval call fun x fun
  • 如何使用 Reactable 过滤父表和嵌套表中的行?

    如何过滤具有特定内容的行Type 它们位于父表或任何嵌套表中reactable using crosstalk filter checkbox 如图所示here https glin github io reactable articles
  • [R][传单]:点击超链接

    我想在世界地图上添加标记 当用户单击一个标记时 它会将用户引导到另一个网站 而不是弹出窗口 我是这个库的新手 实际上这是我为了解决这个问题而尝试的第一个库 带有超链接标记的交互式地图 供用户单击并转到另一个网站 所以我能做的就是 map l
  • 将 df 拆分为多列的 **tidyverse** 方法是什么?

    我想将数据框分成多列 以便我可以看到summary 数据每个子集的输出 这是一种使用方法来做到这一点split from base library tidyverse gt Loading tidyverse ggplot2 gt Load
  • R包导出ICS?

    有谁知道 R 函数可以将日期和标签导出为 ics 日历格式 我已经用谷歌搜索过 但没有什么是显而易见的 但不敢相信有人还没有这样做 iCalendar 规范是非常简单 https www rfc editor org rfc rfc2445
  • RcppEigen 包“#pragma clang Diagnostic pop”警告

    我在尝试使用时遇到一些问题RcppEigen包裹 我使用了发布的示例here http gallery rcpp org articles eigen eigenvalues 该函数有效 但 R 生成了一系列类似的警告 示例如下 In fi
  • 如何在 Windows 操作系统上安装 BigMemory 和 bigrf

    我一直在尝试在我的 R 安装上安装 bigmemory 我的操作系统是 windows 7 64 位 我已经在 R V2 15 1 2 15 2 和 3 0 1 64 位上尝试过 但我无法让它工作 我尝试了几种选择 下载当前源并在 R v3
  • glm 起始值不被接受日志链接

    我想运行带有日志链接和偏移量的高斯 GLM 出现以下问题 y lt c 1 1 0 0 t lt c 5 3 2 4 没问题 exp coef glm y 1 offset log t family poisson with family
  • 将函数应用于数据框的所有元素

    我正在尝试对数据框中的所有元素应用一些转换 当使用常规应用函数时 我得到一个矩阵而不是数据帧 有没有办法直接获取数据框而不添加as data frame到每一行 df data frame a LETTERS 1 5 b LETTERS 6
  • 约束优化 R:另一个例子

    我正在尝试在 R 中执行约束优化 我已经查看了这些帖子和其他一些帖子 R 中的约束优化 https stackoverflow com questions 5436630 constrained optimization in r R 中的
  • 在 R heatmap.2 中移动颜色键(gplots 包的功能)

    我现在阅读了 heatmap 2 帮助手册几次 并且在各种在线教程中我也没有读到有关将颜色键移动到不同位置的方法 现在 我想知道这是否可能 如果您使用 gplots 包中的 heatmap 2 函数 则默认情况下颜色键位于左上角 中每个元素
  • Rscript 正在绘制 PDF

    我有一个简单的R http en wikipedia org wiki R 28programming language 29脚本 当它通过 Rscript exe 运行时 默认情况下它会绘制为 PDF 文件 我希望脚本打开一个绘图窗口 我
  • 保存/加载 data.table 的最快方法

    我想做的实际上是使用最快的可用方法来存储data table以便进一步处理 大致如下 从 CSV RDS 读取原始数据 将其转换为data table 将其保存为针对重新读取而优化的格式 RDS 似乎不适用于data table 是对的吗
  • 在闪亮仪表板中显示/隐藏菜单项

    当进入应用程序时 我需要隐藏一个菜单项 当用户选择某个值时 菜单项必须出现 我努力了shinyjs功能hidden 并且它隐藏了一个 menuItem 但是当使用show or toggle 菜单项不会出现 我发现了Rshinydashbo
  • 在 R 中使用两个 for 循环创建矩阵/数据框

    这是我在 SO 上的第一篇文章 所以请友善 我的问题与这个问题隐约相关 R中的双for循环创建矩阵 https stackoverflow com questions 44376020 double for loop in r creati
  • 评估 R 中字符串指向的函数

    假设我有以下内容 x lt 1 10 squared lt function x x 2 y lt squared 我希望能够使用 y 定义的字符串来评估该函数 像 eval y 这样的东西 我知道这是错误的 但会返回 1 1 4 9 16
  • 使用 geom_bar 和 stat="identity" 绘制平均值的 hline

    我有一个条形图 其中确切的条形高度位于数据框中 df lt data frame x LETTERS 1 6 y c 1 6 1 6 1 g rep x c a b each 6 ggplot df aes x x y y fill g g
  • 有没有办法将字母扩展到超过 26 个字符,例如 AA、AB、AC...?

    我大部分时间都使用字母来表示我的因素 但今天我尝试超过 26 个字符 LETTERS 1 32 期待有自动递归因式分解 AA AB AC 但很失望 这只是字母的限制还是有办法使用其他函数来获取我正在寻找的内容 702够吗 LETTERS70
  • 哪种 LaTeX 包与 knit 一起使用以获得更多的表格控制?禁忌?

    我正在用 knitr 写一张更长的桌子xtable和tabular environment longtable 在 longtable 包中时print将它们纳入我的 Rnw file 问题是我对longtable环境控制不够 我有一些文本

随机推荐