Skip to content

Instantly share code, notes, and snippets.

@webbedfeet
Created May 17, 2013 02:12
Show Gist options
  • Save webbedfeet/5596476 to your computer and use it in GitHub Desktop.
Save webbedfeet/5596476 to your computer and use it in GitHub Desktop.
Ensure left continuity of a function
# Ensure left continuity of a decreasing step function
# First find discontinuities, based on minimum jump size, then make sure there
# is a data point to ensure left continuity there.
lcts <- function(dat, min.jump){
for(i in 2:nrow(dat)){
if(dat[i+1,2] - dat[i,2] > min.jump){ # identify discontinuity
dat <- rbind(dat, c(dat[i+1,1], dat[i,2])) # generate left-cts data point
}
}
dat <- dat[order(dat[,1]),]
return(dat)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment