Skip to content

Instantly share code, notes, and snippets.

@aammd
Created February 16, 2016 23:22
Show Gist options
  • Save aammd/85152756f12c097b9e0f to your computer and use it in GitHub Desktop.
Save aammd/85152756f12c097b9e0f to your computer and use it in GitHub Desktop.
library(rvest)
st_tab <- read_html("https://en.wikipedia.org/wiki/List_of_Star_Trek_characters") %>%
html_nodes(".wikitable td , .wikitable th") %>%
html_text()
library(stringr)
titles <- st_tab %>%
str_detect(regex("^\\n.*\\n$", perl = TRUE))
st_tab[titles]
which(titles)
st_tab_ds9 <- st_tab[seq(which(titles)[4]+1, to = which(titles)[5]-1)]
character_matrix <- matrix(st_tab_ds9, ncol = 7, byrow = TRUE)
library(dplyr)
ds9_char_df <- data.frame(character_matrix[-1,]) %>%
setNames(character_matrix[1,]) %>%
dplyr::tbl_df()
ds9_char_df %>% glimpse
library("gender")
library(tidyr)
ds9_char_df %>%
select(Actor) %>%
mutate(FirstName = str_match(Actor, "[A-Za-z]+"))
gender("Nana",years = c(1970,2011))
ds9_char_df %>% select(Actor) %>% .[[1]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment