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
| # install.packages("googlesheets") | |
| suppressMessages(library(dplyr)) | |
| library(googlesheets) | |
| library(dplyr) | |
| gs_url("https://docs.google.com/spreadsheets/d/1IbDM8z5XicMIXgr93FPwjgwoTTKMuyLfzU6cQrGZzH8/pub?gid=0",lookup = FALSE) | |
| ## Sheet-identifying info appears to be a browser URL. | |
| ## googlesheets will attempt to extract sheet key from the URL. | |
| ## Putative key: 1IbDM8z5XicMIXgr93FPwjgwoTTKMuyLfzU6cQrGZzH8 |
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
| extract_key_from_url("https://docs.google.com/spreadsheets/d/1IbDM8z5XicMIXgr93FPwjgwoTTKMuyLfzU6cQrGZzH8/pub?gid=0") | |
| ## [1] "1IbDM8z5XicMIXgr93FPwjgwoTTKMuyLfzU6cQrGZzH8" |
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
| gs_key("1IbDM8z5XicMIXgr93FPwjgwoTTKMuyLfzU6cQrGZzH8", verbose=FALSE, lookup = FALSE) | |
| ## Spreadsheet title: indicator gapminder population | |
| ## Spreadsheet author: gapdata | |
| ## Date of googlesheets registration: 2015-10-05 16:54:10 GMT | |
| ## Date of last spreadsheet update: 2012-09-07 13:50:39 GMT | |
| ## visibility: public | |
| ## permissions: rw | |
| ## version: new | |
| ## |
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
| gdp_per_capita <- gs_key("phAwcNAVuyj1jiMAkmq1iMg",lookup = FALSE, verbose=FALSE) %>% gs_read(ws = "Data", check.names=FALSE) | |
| ## Accessing worksheet titled "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
| df2 <- gs_key("phAwcNAVuyj1jiMAkmq1iMg",lookup = FALSE, verbose=FALSE) %>% gs_read(ws = "Data", range = "A1:D8") | |
| ## Accessing worksheet titled "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
| df2 %>% rename_(.dots=setNames(names(.), (gsub("X", "", names(.))))) | |
| ## Source: local data frame [7 x 4] | |
| ## | |
| ## GDP.per.capita 1800 1801 1802 | |
| ## (chr) (chr) (chr) (chr) | |
| ## 1 Abkhazia NA NA NA | |
| ## 2 Afghanistan 634.4000136 634.4000136 634.4000136 | |
| ## 3 Akrotiri and Dhekelia NA NA NA | |
| ## 4 Albania 860.5879664 861.4817538 862.3764694 |
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
| head(gdp_per_capita)[1:5] | |
| ## Source: local data frame [6 x 5] | |
| ## | |
| ## GDP per capita 1800 1801 1802 1803 | |
| ## (chr) (dbl) (dbl) (dbl) (dbl) | |
| ## 1 Abkhazia NA NA NA NA | |
| ## 2 Afghanistan 634.400 634.4000 634.4000 634.4000 | |
| ## 3 Akrotiri and Dhekelia NA NA NA NA | |
| ## 4 Albania 860.588 861.4818 862.3765 863.2721 |
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
| colnames(gdp_per_capita)[1] | |
| ## [1] "GDP per capita" | |
| colnames(gdp_per_capita)[1] <- c("Country") |
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
| child_mortality <- gs_key("0ArfEDsV3bBwCcGhBd2NOQVZ1eWowNVpSNjl1c3lRSWc",lookup = FALSE, verbose=FALSE) %>% gs_read(ws = "Data", check.names=FALSE) | |
| ## Accessing worksheet titled "Data" | |
| democracy_score <- gs_key("0ArfEDsV3bBwCdGQ2YlhDSWVIdXdpMmhLY2ZZRHdNNnc",lookup = FALSE, verbose=FALSE) %>% gs_read(ws = "Data", check.names=FALSE) | |
| ## Accessing worksheet titled "Data" | |
| life_expectancy <- gs_key("tiAiXcrneZrUnnJ9dBU-PAw",lookup = FALSE, verbose=FALSE) %>% gs_read(ws = "Data", check.names=FALSE) | |
| ## Accessing worksheet titled "Data" | |
| population <- gs_key("phAwcNAVuyj0XOoBL_n5tAQ",lookup = FALSE, verbose=FALSE) %>% gs_read(ws = "Data", check.names=FALSE) |
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(RCurl) | |
| ## Loading required package: bitops | |
| countries <- getURL("https://raw.githubusercontent.com/lukes/ISO-3166-Countries-with-Regional-Codes/master/all/all.csv") | |
| countries <- read.csv(text=countries, header = TRUE, stringsAsFactors=FALSE) | |
| countries <- read.csv("data/countries.csv", | |
| header = TRUE, | |
| stringsAsFactors= FALSE, check.names=FALSE) | |
| countries <- tbl_df(countries) | |
| str(countries)[1:5] |
OlderNewer