Skip to content

Instantly share code, notes, and snippets.

Arvi Sreenivasan arvi1000

Block or report user

Report or block arvi1000

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View crank_beauty.R
# survey of crank beauty
# https://forms.gle/CNqHkmeQa6n1cJxL7
library(tidyverse)
library(data.table)
library(patchwork)
# data ----
"DA 7400 DA 7700 DA 7800 DA 7900 DA 9000 DA 9100
8 7 6 2 5 4
View delegates.R
library(ggplot2)
library(data.table)
dat <- fread(
'name, delegates
"BUTTIGIEG", 22
"SANDERS", 21
"WARREN", 8
"KLOBUCHAR", 7
"BIDEN", 6
"Still\nremaining", 3915')
View little_women_names.R
library(babynames)
library(tidyverse)
bab <- babynames %>% filter(sex=="F" & year >= 1945)
bab$rgx_match <- as.character(NA)
for(i in c('Amy', 'Beth', 'Meg', 'Jo')) {
rgx <- paste0('^', i, '.*$')
bab$rgx_match <- coalesce(
ifelse(grepl(rgx, bab$name), rgx, NA),
View handlebars.R
library(data.table)
library(tidyverse)
library(ggrepel)
"Model, reach, drop, grams
Zipp sl88, 88, 130, 275
Fizik r3 snake, 85, 140, 245
RH Maes P, 115, 125, 298
VO course, 115, 125, 395
Ritchey NeoClassic, 73, 128, 260
View weight_weenie.R
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),
@arvi1000
arvi1000 / bcc_census.R
Last active Dec 13, 2019
How many bikes histogram
View bcc_census.R
library(tidyverse)
dat <-
"name, bike_count
Reid, 4
John, 3
The_Meat, 8
MatthewS, 2
Pinche, 4
arvi1000, 4
@arvi1000
arvi1000 / srt_sort.R
Last active Nov 19, 2019
script to fix an out-of-order .srt caption file
View srt_sort.R
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
View boxplot_example.R
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() +
@arvi1000
arvi1000 / label_colors.R
Created Oct 11, 2019
Changing label colors with rGridMap
View label_colors.R
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',
View zach_alt_spelling.R
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 %>%
You can’t perform that action at this time.