Skip to content

Instantly share code, notes, and snippets.

View ClaytonJY's full-sized avatar
🏂

Clayton Yochum ClaytonJY

🏂
View GitHub Profile
@ClaytonJY
ClaytonJY / impute_and_sum_demo.R
Last active March 10, 2019 17:26
Add column in base R, imputing with zeros
df <- data.frame(
id = 1:5,
label = LETTERS[1:5], # A, B, C, D, E
gen_1 = c(1.0, 1.1, NA, 1.3, NA),
gen_2 = c(2.0, NA, 2.2, 2.3, NA),
gen_3 = c(3.1, NA, 3.2, NA, NA)
)
# take a look
df
@ClaytonJY
ClaytonJY / group-and-summarize.md
Last active October 31, 2019 02:59
Adding impact factor
library(tidyverse)

# fake some data
input_tbl <- lst(
  MarketDay = as.Date(c("2016-01-01", "2016-01-02", "2016-01-03")),
  HourEnding = 1:3,
  FuelType = c("Coal", "Gas", "Hydro"),
  Month = 1,  # because only Jan dates
  Region = "North"
@ClaytonJY
ClaytonJY / origin.md
Last active November 12, 2019 04:38
'origin' must be supplied
# built-in function for "today"
Sys.Date()
#> [1] "2019-11-11"

# Dates are actually just integers underneath
# we can coerce to integer to see that version of it
today_days <- as.integer(Sys.Date())
today_days
#&gt; [1] 18211
@ClaytonJY
ClaytonJY / timescale-selection-scans-all-chunks.md
Last active January 28, 2021 00:19
Timescale scans all chunks when joining more than one key!

Timescale Selection Query Plans

I've seen some odd behavior trying to select specific items from Timescale hypertables, which I reproduce here with randomized data.

Setup

We'll need a vanilla Timescale instance; I like Docker.

# start a PG12 instance w/ Timescale 2.0