Skip to content

Instantly share code, notes, and snippets.

View mpettis's full-sized avatar

Matt Pettis mpettis

  • Personal
  • Minneapolis, MN
View GitHub Profile
#!/usr/bin/env Rscript
#library(plyr)
library(dplyr)
library(lubridate)
## Datetimes, 15min increments, that span DST breaks
dt_str <- c(
@mpettis
mpettis / caret-lm-loocv-param-est.md
Created September 23, 2016 20:22
caret: Linear Model parameter estimates (mean and s.e.) via LOOCV
@mpettis
mpettis / plyr-and-dplyr.md
Last active October 12, 2016 16:21
plyr example refrence, compare to base functions, no dplyr yet.
@mpettis
mpettis / fourier-fft-periodogram-pick-components.R
Created August 11, 2017 15:39
Fourier DFT FFT reconstruction from important periodogram contributions
## This is just a quick exploration, answering the question:
## How do I reconstruct a signal by picking the highest-power frequency from a periodogram?
## Assumes I keep the constant (DC) term.
## -----------------------------------------------------------------------------
## Fourier decomposition exploration
## -----------------------------------------------------------------------------
x <- 10 * sin(2 * pi * (1:75) / 25) + 300 + rnorm(1:75, 0, 2.5)
x
@mpettis
mpettis / gist:baca4c428a8ab499b98b513e7fa3255e
Last active October 12, 2017 23:49
R: Time Interval Consolidation of Overlaps
Very procedural code, but works. If I have a set of time intervals (lubridate intervals), and I want to consolidate any chain of overlapping intervals into a single interval with left end the min of all start times and right side as max of all end times, this is the code to do that.
``` r
## Consolidating intervals
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(lubridate))
# In this table of intervals, rows 3,4, and 5 form a chain of intervals. They should be rolled into 1 interval.
# And note rows 3 and 5 do not themselves overlap, but they are chained together by having overlap with row 4.
---
title: "R-user-group_tidyr-talk"
author: "Matt Pettis"
date: "November 22, 2017"
always_allow_html: yes
output:
html_document:
toc: true
---