Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# dplyr package
install.packages("dplyr")
library(dplyr)
# review page structure
glimpse(page)
# select these four columns for our analysis
small_page <- page %>% select(type, like=likes_count, comment=comments_count, share=shares_count)
small_page$type <- as.factor(small_page$type)
# do some deeper analysis
# 1. compute the ratio of share per like
small_page %>%
mutate(like = like + 1, share = share + 1) %>%
mutate(ratio_share_like = share / like) %>%
summarise(avg_ratio = mean(ratio_share_like),
median_ratio = median(ratio_share_like),
max_ratio = max(ratio_share_like),
min_ratio = min(ratio_share_like))
# 2. what kind of content get most likes
small_page %>%
group_by(type) %>%
summarise(avg_like = mean(like)) %>%
arrange(desc(avg_like))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment