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
## -------------------------- ## | |
## 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){ |
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
# 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 | |
} |
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(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) |
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
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 |
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
# 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 |
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) | |
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 |
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
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: |
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
# 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), |
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
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") |
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://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)), |
OlderNewer