我正在使用唐纳德特朗普推文的公共数据集,可以在这里找到:https://www.kaggle.com/kingburrito666/better-donald-trump-tweets
在这样做之后,我试图按照R中的日期对它进行分组。首先,我想计算一下推文的数量。第二天,我想总结一下“收藏”和“转推”。天。
我写了下面的代码,但它一直给我错误......你能帮助我吗?
提前致谢!
Donald <- read_csv(file="Donald-Tweets!.csv")
Donald
#Grouped
G_filter <- Donald %>%
select(Date,twt_favourites_IS_THIS_LIKE_QUESTION_MARK, Retweets) %>%
rename( Favourites = twt_favourites_IS_THIS_LIKE_QUESTION_MARK) %>%
group_by(as.Date.date(Date)) %>%
summarise(Total = sum(Favourites+Retweets), count(n))
View(G_filter)
这可能就是你要找的东西。
library(tidyverse)
G_filter <- Donald %>%
select(Date, twt_favourites_IS_THIS_LIKE_QUESTION_MARK, Retweets) %>%
rename(Favourites = twt_favourites_IS_THIS_LIKE_QUESTION_MARK) %>%
group_by(Date) %>%
mutate(Favorites_and_Retweets = Favourites + Retweets) %>%
summarise(Favorites_and_Retweets = sum(Favorites_and_Retweets),
Count = n())
G_filter
# # A tibble: 479 x 3
# Date Favorites_and_Retweets Count
# <chr> <int> <int>
# 1 15-07-16 66899 39
# 2 15-07-17 65212 22
# 3 15-07-18 97381 32
# 4 15-07-19 34229 12
# 5 15-07-20 62316 37
# 6 15-07-21 88132 62
# 7 15-07-22 69919 37
# 8 15-07-23 67963 43
# 9 15-07-24 67687 35
# 10 15-07-25 39744 25
# # ... with 469 more rows
没有必要转换Date
列。如果你真的想这样做,一种方法是加载lubridate
包,然后在管道中执行mutate(Date = ymd(Date))
。