Skip to content

Instantly share code, notes, and snippets.

View darokun's full-sized avatar

Daloha Rodriguez-Molina darokun

  • Munich, Germany
View GitHub Profile
@darokun
darokun / shadenorm.R
Last active November 5, 2015 15:14 — forked from tony91782/shadenorm.R
## -------------------------- ##
## An R Function that Shades ##
## under a normal density. ##
## ##
## This is a convenience ##
## function for polygon() ##
## -------------------------- ##
shadenorm = function(below=NULL, above=NULL, pcts = c(0.025,0.975), mu=0, sig=1, numpts = 500, color = "gray", dens = 400,
lines=FALSE,between=NULL,outside=NULL){
@darokun
darokun / SqTri.R
Created February 23, 2017 13:20
Finding square numbers that are also triangular numbers
# Finding square numbers that are also triangular numbers
# This snippet of code has been inspired by Matt Parker's book: Things to make and do in the fourth dimension, Chapter 3, pg. 50
# Square numbers
SqNum <- function(to, from = 1) {
x <- NULL
for(i in seq(from = from, to = to)) {
x[i] <- i^2
}
@darokun
darokun / distinctColors.R
Last active August 1, 2020 04:53
Generating different and distinct colors in R
library(RColorBrewer)
qual_col_pals <- brewer.pal.info[brewer.pal.info$category == 'qual',]
col_vector <- unlist(mapply(brewer.pal, qual_col_pals$maxcolors, rownames(qual_col_pals)))
#check
myunif <- runif(40, 1, 1)
barplot(myunif, col = col_vector)
@darokun
darokun / berlin_wall.R
Created February 6, 2018 08:31
Has the Berlin Wall been down longer than it stood? By how much?
construction <- as.Date("1961-08-13")
fall <- as.Date("1989-11-09")
now <- as.Date("2018-02-06")
now-fall > fall-construction
fall-construction
now-fall
# Based on this blog post: https://www.r-bloggers.com/updating-r/
### 1
## Change accordingly
list_dir <- "/Library/Frameworks/R.framework/Resources/library"
## Get the list of installed packages
installed <- dir(.libPaths())
## Save the list for later use
@darokun
darokun / clean_adobe_connect_session_grading_data.R
Created April 27, 2018 11:04
This is a gist to clean the spreadsheet containing grades for my students on Adobe Connect sessions
library(tidyverse)
library(readxl)
library(stringr)
xl_data <- read_excel("Feedback_Job_Interview.xlsx")
col_names <- c("student", "date", "preparation", "fluency", "grammar", "vocabulary", "questions", "grade", "comments")
colnames(xl_data) <- col_names
@darokun
darokun / f.R
Created September 25, 2018 12:40
ANOVA year older
install.packages("extrafont")
install.packages("extrafontdb")
library(extrafont)
library(extrafontdb)
library(ggplot2)
# make sure to install the desired font in the computer at this point
# then:
# from a tweet I found around, by @WeAreRLadies maybe?
x <- 1:4
y <- 3:6
compare <- function(x, y) {
list(
"These values are in x but not in y" = setdiff(x, y),
"These values are in y but not in x" = setdiff(y, x),
"These values are shared between x and y" = intersect(x, y),
@darokun
darokun / cals_with_calendR
Last active December 1, 2020 14:57
Create 2020 and 2021 calendars to keep track of daily activities by crossing out days
pacman::p_load(tidyverse, suncalc, ggimage, lubridate)
src_calendR <- "https://raw.githubusercontent.com/R-CoderDotCom/calendR/master/R/calendR.R"
download.file(src_calendR, "calendR.R")
source("calendR.R") # installing package doesn't work in my system (old R version), sourcing instead.
days_until_20201130 <- seq(ymd("20200101"), ymd("20201130"), "days")
### habits to track
# arms
calendR(orientation = "landscape", pdf = TRUE, doc_name = "arms_cal2020", special.days = 1:length(days_until_20201130), special.col = "black", low.col = "white", title = "arms 2020")
calendR(year = 2021, orientation = "landscape", pdf = TRUE, doc_name = "arms_cal2021", title = "arms 2021")
# data from http://www.edisonresearch.com/wp-content/uploads/2017/04/Podcast-Consumer-2017.pdf
library(tidyverse)
set.seed(20210311)
podcast_women <- tibble(
gender = rep("female", 2000*.44),
y2013 = sample(c("yes", "no"), size = 2000*.44, replace = TRUE, prob = c(0.09, 1 - 0.09)),
y2014 = sample(c("yes", "no"), size = 2000*.44, replace = TRUE, prob = c(0.13, 1 - 0.13)),
y2015 = sample(c("yes", "no"), size = 2000*.44, replace = TRUE, prob = c(0.16, 1 - 0.16)),
y2016 = sample(c("yes", "no"), size = 2000*.44, replace = TRUE, prob = c(0.18, 1 - 0.18)),