使用来自csv文件的R过滤数据

问题描述 投票:-1回答:1

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

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

我想知道哪些comment_author评论最多(comment_message#)和Sentiment > 0

有人知道如何使用R来应用这个过滤器吗?

r excel csv sorting filter
1个回答
0
投票

如果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变量做什么(例如你需要提供一个例子),但分组部分已完成

© www.soinside.com 2019 - 2024. All rights reserved.