Skip to content

Instantly share code, notes, and snippets.

@toyeiei
Last active February 8, 2019 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toyeiei/c01249cce4e6d15bfd8f250fd63b7712 to your computer and use it in GitHub Desktop.
Save toyeiei/c01249cce4e6d15bfd8f250fd63b7712 to your computer and use it in GitHub Desktop.
# 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