Created
October 17, 2016 18:22
-
-
Save 3rdworldjuander/fd1a5f7064479d611c8dfb5e951f8a49 to your computer and use it in GitHub Desktop.
wordpress testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(stringr) | |
library(tidyr) | |
edges <- stream %>% filter(is.na(`User Mentions`) == F) %>% | |
select(Nickname, `Is a RT`, `User Mentions`) | |
#tagging retweets and mentions | |
edges <- edges %>% | |
dplyr::mutate( type = ifelse(edges$`Is a RT` == TRUE, | |
"retweet", "mention")) %>% | |
select(-`Is a RT`) | |
#finding maximum length of User Mentions | |
menMax <- max(str_count(edges$`User Mentions`, "@")) | |
edges <- edges %>% | |
separate(`User Mentions`, c(as.character(1:menMax)), | |
",", extra = "merge", fill = "left") | |
#gathering all users mentioned into one column | |
edges <- edges %>% gather(from_col, to, 2:13 ) | |
#cleaning NAs and removing from_col | |
edges <- edges %>% filter(is.na(to) == FALSE) %>% select(from = Nickname, to, type) | |
#remove @ signs | |
edges$to <- gsub('@','', edges$to) | |
#solve: count unique rows based on multiple columns??? | |
links <- aggregate(rep(1, nrow(edges)), by = list(from = edges$from, to = edges$to, type = edges$type), sum) | |
links <- links[order(links$from, links$to),] | |
colnames(links)[4] <- "weight" | |
rownames(links) <- NULL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment