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
--- | |
title: "R Notebook" | |
output: html_notebook | |
--- | |
```{r} | |
library(tidyverse) | |
library(lubridate) | |
``` |
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
--- | |
title: "R Notebook" | |
output: html_notebook | |
--- | |
```{r} | |
library(tidyverse) | |
library(animation) |
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
# Pasted from various sources and published quickly as part of a twitter discussion; not tested if this copy/paste actually runs. | |
# Result as https://twitter.com/hnrklndbrg/status/859888911337873409 | |
library(tidyverse) | |
library(lubridate) | |
df.recent <- read_csv2('/home/henrik/private/vizyns/data/väder/göteborg-a-20170502.csv', skip=15) %>% | |
transmute(date=`Representativt dygn`, | |
min=as.numeric(`Lufttemperatur`), | |
max=as.numeric(`Lufttemperatur_1`)) |
We can make this file beautiful and searchable if this error is corrected: It looks like row 8 should actually have 1 column, instead of 2 in line 7.
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
code;name | |
01;Personal Care Activities | |
0101;Sleeping | |
0102;Grooming | |
0103;Health-related self care | |
0104;Personal Activities | |
0105;Personal Care Emergencies | |
0199;Personal care, n.e.c.* | |
02;Household Activities | |
0201;Housework |
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(htmltab) | |
library(tidyverse) | |
library(stringr) | |
URL <- 'https://en.wikipedia.org/w/index.php?title=Global_Terrorism_Index&oldid=779504863' | |
df <- htmltab(URL, 5) %>% | |
transmute(Country = str_trim(Country), | |
score = as.numeric(Score)) |
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
# Data from https://www.kaggle.com/bls/american-time-use-survey | |
library(tidyverse) | |
library(tidytext) | |
# Contains both 1st and 2nd level codes; collisions won't appear though since 1-99 is tier 1 and 100+ is two | |
df.names <- read_csv2('../data/atus/codes.csv') %>% | |
mutate(code = as.integer(code)) | |
df.resp <- read_csv('../data/atus/atusresp.csv') |
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(tidyverse) | |
# data from https://www.kaggle.com/bls/american-time-use-survey | |
df.resp <- read_csv('../data/atus/atusresp.csv') | |
df.act <- read_csv('../data/atus/atusact.csv', col_types=cols(tustarttim = col_character(), tustoptime = col_character())) | |
df.sum <- read_csv('../data/atus/atussum.csv') | |
df.tmp <- df.act %>% | |
mutate(activity = case_when(trtier2p == 1301 ~ 'Exercise', |
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
# Download elevation tif from eg http://www.eea.europa.eu/data-and-maps/data/digital-elevation-model-of-europe | |
# First, convert elevation tif to a space delimited xyz (lng lat elevation) file | |
# $ gdal_translate -of XYZ elevation3x3.tif /tmp/file.xyz | |
df <- read_delim('/tmp/file.xyz', delim=' ', col_names=FALSE) | |
df %>% | |
mutate(X3 = na_if(X3, 0)) %>% | |
ggplot(aes(X1, -X2 + 20 * X3/max(X3, na.rm=TRUE), group=X2)) + | |
geom_line(size=0.05) + |
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
# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat | |
# Originally seen at http://spatial.ly/2014/08/population-lines/ | |
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess, | |
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after | |
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line. | |
# The result of the code below can be seen at http://imgur.com/ob8c8ph | |
library(tidyverse) |
NewerOlder