Let's say I have a large dataset of numeric values:
big_dataset = rnorm(n = 500, mean = 20, sd = 10)
I want to pull out a subset of observations from big_dataset
that have similar values (within 5 units) to those in an existing and independent dataset:
independent_dataset = runif(n = 20, min = 0, max = 100)
That way both my newly made subset and independent_dataset
are comparable. What's a good way to do this?
All I can come up with is an apply loop that searches iteratively for something close to each value in independent_dataset
but I thought there might be a more elegant way...
Probably you can try