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(tidyverse) | |
adj_ftp <- function(rider_kg=70, watts_kg_ftp=3, extra_kg) { | |
watts <- watts_kg_ftp * rider_kg | |
adj_wkf <- watts / (rider_kg + extra_kg) | |
return(adj_wkf) | |
} | |
tibble(extra_kg = seq(0, 5, .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
library(tidyverse) | |
dat <- | |
"name, bike_count | |
Reid, 4 | |
John, 3 | |
The_Meat, 8 | |
MatthewS, 2 | |
Pinche, 4 | |
arvi1000, 4 |
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
setwd('~/Documents/personal/r_stuff/bcc/srt_sort/') | |
# processing function. input is lines of the file as char vector | |
fix_srt <- function(srt_file) { | |
# caption chunks are delimited by a blank line ''. | |
# so... add a blank line to the start | |
srt_file <- c('', srt_file) | |
# ...now the cumulative sum of blanks so far is a vector we can split on |
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(tidyverse) | |
lapply(1:5, function(x) { | |
data.frame(team = LETTERS[x], | |
alignment_score = rnorm(20, mean=max(x, 3), sd=0.5), | |
stringsAsFactors = F) | |
}) %>% | |
bind_rows() %>% | |
ggplot(aes(x=team, y=alignment_score)) + | |
geom_boxplot() + |
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
devtools::install_github('arvi1000/rGridMap') | |
library(rGridMap) | |
library(ggplot2) | |
# a data.frame of states with random categorical value | |
set.seed(123) | |
my_dat <- data.frame(state.abb = c(state.abb, 'DC'), # don't forget DC! | |
value=sample(LETTERS[1:5], 51, replace=T)) | |
plotGridMap(my_dat, fill_var = 'value', |
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(tidyverse) | |
# zachary / zachery by year | |
z_dat <- babynames::babynames %>% | |
filter(grepl('^zach(a|e)ry$', tolower(name)) & year >= 1950) %>% | |
group_by(name, year) %>% | |
summarise(n=sum(n)) | |
# when was peak zachary? 1993 | |
z_dat %>% |
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
just to rename gist |
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(tidyverse) | |
# Prep data | |
# data from https://poll.qu.edu/texas/release-detail?ReleaseID=2625 | |
dat <- | |
"challenger, d_pct, trump_pct | |
Biden, 48, 44 | |
Sanders, 44, 47 | |
Warren, 45, 46 | |
Harris, 43, 47 |
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(babynames) | |
library(tidyverse) | |
library(ggrepel) | |
dat <- babynames %>% | |
filter(sex=='M') %>% | |
mutate(chars = nchar(name), | |
last_char = substr(name, chars, chars)) %>% | |
group_by(year, last_char) %>% | |
summarise(prop = sum(prop)) |
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(babynames) | |
library(tidyverse) | |
babynames::babynames %>% | |
filter(name=='Arya') %>% | |
ggplot(aes(x=year, y=prop*100, color=sex)) + | |
geom_line(size=1) + | |
labs(title = 'Babies Named Arya', | |
subtitle = 'as a proportion of all births that year', | |
y='%') + |