【问题标题】:Filter data with R from csv file使用 R 过滤来自 csv 文件的数据
【发布时间】:2018-06-09 10:20:18
【问题描述】:

我有一个包含大约 190,000 行的 Facebook 数据的 csv 文件。列名如下:

comment_id, status_id, parent_id, comment_message, comment_author, comment_published, comment_likes, Positive, Negative, Sentiment

我想找出哪个 comment_author 拥有最多的 cmets(# of comment_message)和一个 Sentiment > 0

有人知道如何使用 R 应用此过滤器吗?

【问题讨论】:

标签: r excel csv sorting filter


【解决方案1】:

如果df 是您的数据框,您可以使用dplyr 包,如下所示:

df %>% group_by(comment_author,sentiment) %>%
       dplyr::summarize(total_number_comment=sum(comment_message)) %>%
       as.data.frame() %>%
       arrange(desc(total_number_comment)) %>%
       filter(sentiment>0)

我不明白你真正想用sentiment 变量做什么(例如你需要提供一个例子),但是分组部分已经完成了

【讨论】:

  • 非常感谢您的快速帮助!情绪显示从 -5 到 5 的数字,其中 0 是中性的。例如 -5 表示评论非常负面。我尝试使用您建议的代码,但我总是收到错误消息: df %>% group_by(comment_author, Sentiment) %>% dplyr::summarize(total_number_comment = sum(comment_message)) %>% : could not find function "%>%" 你知道我做错了什么吗?我必须在您的代码中添加一些内容吗?在此先感谢:-)
  • @lzed 你安装了 dplyr 库吗?只需在您的代码库(“dplyr”)之前使用
猜你喜欢
  • 1970-01-01
  • 2018-05-17
  • 2016-12-31
  • 2018-10-08
  • 1970-01-01
  • 1970-01-01
  • 2020-08-18
  • 2021-05-14
  • 1970-01-01
相关资源
最近更新 更多