Skip to content

Instantly share code, notes, and snippets.

@wdkrnls
Last active January 17, 2017 04:06
Show Gist options
  • Save wdkrnls/e08010d6ec2c30e9ba53f73f111a881b to your computer and use it in GitHub Desktop.
Save wdkrnls/e08010d6ec2c30e9ba53f73f111a881b to your computer and use it in GitHub Desktop.
# all.equal does a lot, nearly_equal does little.
nearly_equal <- function(x, y, tol = sqrt(.Machine$double.eps)) y < x + tol & y > x - tol
# syntax can be confusing to beginners
which_is <- function(x, test) x[which(test)]
x <- seq(0, 2*pi, by = 0.01)
library(magrittr)
x %>% which_is(nearly_equal(sin(x), 0.5, tol = 0.005))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment