Last active
October 10, 2020 14:33
-
-
Save thoolihan/f656ccb37c551807e063ab2538fb4aeb to your computer and use it in GitHub Desktop.
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
data <- -10:10 | |
lims <- range(data) | |
x <- sample(data, 50, replace = TRUE) | |
par(mfrow=c(1, 5)) | |
plot(x, ylim=lims, main="initial data") | |
# only positive | |
plot(pmax(x, 0), ylim=lims, main="clip bottom") | |
# only negative | |
plot(pmin(x, 0), ylim=lims, main="clip top") | |
# clip 1-3 | |
plot(pmax(pmin(x,3), 1), ylim=lims, main="nested pmax & pmin") | |
clip <- function(x, lower, upper) { | |
pmax(pmin(x, upper), lower) | |
} | |
plot(clip(x, 1, 3), ylim=lims, main="clip function") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment