This file contains hidden or 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(dplyr); library(httr); library(rvest) | |
| addr <- "Big Ben" | |
| GET("http://maps.google.com/maps/api/geocode/xml", | |
| query = list(address = addr)) %>% | |
| content() %>% | |
| html_nodes(xpath = "//location//lat | //location//lng") %>% | |
| html_text() %>% | |
| setNames(c("lng", "lat")) |
This file contains hidden or 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(eurostat) | |
| library(dplyr) | |
| library(ggplot2) | |
| library(scales) | |
| #### Original version (not using %+%) #### | |
| # Originally posted at http://www.r-bloggers.com/european-debt-and-interest/ on June 7, 2015 | |
| r1 <- get_eurostat('gov_10dd_edpt1') |
This file contains hidden or 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
| # Using ldply returns a clean data frame, so avoids | |
| # the lapply + do.call(rbind, ...) idiom | |
| # Also, the .progress argument is very useful | |
| df <- ldply(c(2002:2014, 52, 26, 13, 4, 1), function(x) { | |
| sprintf("http://distrowatch.com/index.php?dataspan=%d", x) %>% | |
| html() %>% | |
| html_nodes(xpath = | |
| "//table[@class = 'News' and @style = 'direction: ltr'][2]") %>% | |
| .[[1]] %>% |
This file contains hidden or 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
| lapply(c("dplyr", "xml2", "rvest", "stringr", "ggplot2"), library, | |
| character.only = TRUE) | |
| url <- "https://en.wikipedia.org/wiki/Fatal_dog_attacks_in_the_United_States" | |
| page <- read_html(url) | |
| # Each year is represented by its own table | |
| tbls <- page %>% | |
| xml_find_all("//table") %>% |
This file contains hidden or 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
| lapply(c("WDI", "dplyr", "stringr", "ggplot2", "tidyr", "ggthemes"), library, | |
| character.only = TRUE) | |
| library(wvs) # local package | |
| # Get shares who mentioned specific groups when asked who they would not want | |
| # as a neighbour | |
| values <- wvs %>% | |
| filter(wave %in% c("2005-2009", "2010-2014")) %>% | |
| group_by(country.abbreviation) %>% |
This file contains hidden or 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(lubridate) | |
| library(ggplot2) | |
| period_name <- c(month.name, as.character(wday(1:7, label = TRUE, abbr = FALSE))) | |
| name_length <- sapply(strsplit(period_name, ""), length) | |
| df <- data.frame(period_name, name_length, period_order = c(1:12, 1:7), | |
| type = rep(c("Months", "Weekdays"), c(12, 7))) | |
| ggplot(df, aes(x = period_order, y = name_length, label = period_name)) + |
This file contains hidden or 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(ggplot2) | |
| library(dplyr) | |
| probs <- seq(0.05, 0.95, each = 0.05) | |
| df <- lapply(probs, rbinom, n = 100, size = 100) %>% | |
| unlist() %>% | |
| data.frame("successes" = .) %>% | |
| mutate(probs = rep(probs, each = 100)) |
This file contains hidden or 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(OECD) | |
| # Retrieve data from OECD for all countries | |
| df <- get_dataset("HEALTH_STAT", list("CICDHOCD.TXCMFETF+TXCMHOTH+TXCMILTX")) %>% | |
| tbl_df() %>% | |
| setNames(tolower(names(.))) | |
| # Get list of dataframes with human-readable descriptions of variables and units | |
| dims <- get_data_structure("HEALTH_STAT") |
This file contains hidden or 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(dplyr) | |
| library(tidyr) | |
| library(ggplot2) | |
| library(lubridate) | |
| library(stringr) | |
| library(rvest) | |
| library(xml2) | |
| library(OECD) | |
| # Get budget and box office data |
This file contains hidden or 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(tools) | |
| library(dplyr) | |
| library(readxl) | |
| library(ggplot2) | |
| library(countrycode) | |
| library(ggthemes) | |
| # Function to download and open Excel files | |
| get_data <- function(url, ...) { |
OlderNewer