Skip to content

Instantly share code, notes, and snippets.

@ha0ye
ha0ye / main.R
Last active June 26, 2020 14:59
EDM simplex calculations test (E = 1)
library(rEDM)
# generate time series
set.seed(42)
ts_length <- 50
x <- rnorm(ts_length)
# pre-compute distance matrix
x_dists <- as.matrix(dist(x))
x_dists <- x_dists[, -ts_length] # last point can't be a nearest neighbor
@ha0ye
ha0ye / generate_sequences.R
Last active August 31, 2021 21:07
generate random sequences without consecutive repeats
f <- function(x)
{
n <- sum(x)
v <- numeric(n)
prev <- NULL
for (i in 1:n)
{
idx <- x > floor(sum(x)/2) # how many counts are > n/2
if (sum(idx) >= 2) # error if more than 2 (impossible?)
{
@ha0ye
ha0ye / zs_dist.R
Created October 20, 2021 23:13
distribution of zodiac signs in US population
library(tidyverse)
library(lubridate)
# modified from https://stackoverflow.com/questions/48026462/writing-r-function-using-lubridate-package-that-takes-dateex-august-14-and
zodiac_sign <- function(input)
{
zodiac_sign_df <- data.frame(Month = c("March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "January", "February"),
Zodiac_Separation_Dt = c(21, 20, 21, 21, 23, 23, 23, 23, 22, 22, 20, 19),
LowerSideZS = c("Pisces", "Aries","Taurus","Gemini","Cancer","Leo","Virgo","Libra","Scorpio","Sagittarius","Capricorn","Aquarius"),
UpperSideZS = c("Aries","Taurus","Gemini","Cancer","Leo","Virgo","Libra","Scorpio","Sagittarius","Capricorn","Aquarius", "Pisces"),