Last active
August 29, 2015 14:08
-
-
Save aammd/116915903bec22906149 to your computer and use it in GitHub Desktop.
This function, based on `rvest`, extracts the Gender, Species, Affilation and Rank for a Star Trek character from the [Star Trek Wiki](http://en.memory-alpha.org/wiki/Portal:Main)
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(rvest) | |
library(magrittr) | |
library(tidyr) | |
library(dplyr) | |
library(stringr) | |
character_data <- function(chname){ | |
paste0("http://en.memory-alpha.org/wiki/", chname) %>% | |
html %>% | |
html_nodes(".wiki-sidebar") %>% | |
html_table(header = FALSE) %>% | |
extract2(1) %>% | |
set_colnames(c("trait", "value")) %>% | |
mutate(trait = gsub(":", "", trait)) %>% | |
filter(trait %in% c("Gender","Species","Affiliation","Rank")) %>% | |
mutate(name = chname) %>% | |
spread(trait, value) | |
} | |
character_data("Kira_Nerys") | |
character_data("Odo") | |
character_data("Worf") | |
character_data("Wesley_Crusher") | |
character_data("Ro_Laren") | |
character_data("Julian_Bashir") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment