Skip to content

Instantly share code, notes, and snippets.

pacman::p_load(tidyverse, rio, magrittr, janitor)
# This is a function for dividing a time series into periods, with allowence for gaps (threshold)
# data = dataset
# variable = time for measurement, e.g. year (duplicates allowed)
# threshold = number of consecutive years (e.g.) allowed missing in a period
# filter_less_than = filters periods with less than N values (not the length from min to max!)
periods <- function(data,
variable,
threshold = 3,
library(pacman)
p_load(tidyverse, magrittr, pxweb, janitor, glmmTMB, brms, emmeans)
options(scipen=999)
psu <- get_pxweb_data(url = "http://api.scb.se/OV0104/v1/doris/sv/ssd/ME/ME0201/ME0201B/Partisympati17",
dims = list(Kon = c('1', '2'),
UtbNivaSUN2000 = c('F', '3', 'K', 'L'),
Partisympati = c('m', 'c', 'l', 'kd', 'mp', 's', 'v', 'SD', 'övr'),
ContentsCode = c('*'),
# Data source: William Harkness, Pennsylvania State University
# README: https://web.archive.org/web/20080426073212if_/http://math.fullerton.edu/mori/Math120/Data/readme%20datasets/readme.html#physical
library(pacman)
p_load(tidyverse, magrittr)
# import("https://web.archive.org/web/20080210005048/http://math.fullerton.edu/mori/Math120/Data/readme%20datasets/ds/physical.txt",
# setclass="tbl") %>%
# clean_names() %>%
# datapasta::tribble_construct() %>% writeLines()
tibble::tribble(
~sex, ~height, ~left_arm, ~rt_arm, ~left_foot, ~rt_foot, ~left_hand, ~rt_hand, ~head_circ, ~nose,
#### Source: https://twitter.com/jayvanbavel/status/1106985394883710978
library(tidyverse)
library(janitor)
tibble::tribble(
~Participant, ~Age, ~Matching.words, ~`Non-matching.words`,
1, 7.5, 14.73, 60.28,
2, 36, 12.76, 22.99,
3, 65, 18.85, 49.79,
4, 68, 26.8, 48.1,
pacman::p_load(tidyverse, rio, magrittr, janitor, lubridate, gsheet)
gsheet2tbl("https://docs.google.com/spreadsheets/d/1BRt-2jMpOBSMwx14JC0RGx6jmDzJCi6KIALV9eSyvtY/edit?usp=sharing") -> timeline
timeline %>%
mutate(Beginning = Beginning %>% dmy(),
End = End %>% dmy) %>%
replace_na(replace = list(End = today())) ->
timeline
@StaffanBetner
StaffanBetner / imdb_tvshow_ratings_plot.R
Last active November 6, 2017 14:39
IMDb TV Show Rating/Votes Plot
install.packages(c("tidyverse", "rvest", "fANCOVA"))
library(tidyverse)
library(rvest)
library(fANCOVA)
imdb_tvshow_ratings_plot <- function(id, votes=FALSE){
obj <- paste("http://www.imdb.com/title/", id, "/epdate", sep = "") %>%
read_html()
obj <- obj %>%
html_table(dec = ",", trim = T) %>%
.[[1]] %>% .[, -5] %>%
joined_dataset %>% filter(vald == 1) %>%
ggplot(aes(
x = F1,
y = F2,
name = Namn,
color = Parti,
group = Parti
)) +
geom_point() +
library(gsheet)
library(tidyverse)
library(magrittr)
library(fANCOVA)
library(Cairo)
#library(plotly)
facialhairstyles <-
gsheet::gsheet2tbl(
"https://docs.google.com/spreadsheets/d/14hgOhTHb5caVmmLwq859U22BlsIBeQyGPV1yAJ74Xms/edit#gid=0"
)