Created
May 17, 2013 02:12
-
-
Save webbedfeet/5596476 to your computer and use it in GitHub Desktop.
Ensure left continuity of a function
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
# 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