I am trying to use match()
in R to find any matching values within a certain interval. For example:
v <- c(2.2, 2.4, 4.3, 1.3, 4.5, 6.8, 0.9)
match(2.4, v)
gives me all the locations where 2.4 occurs in v
, but what if I wanted to give a range for all possible matches? For example 2.4 +/- 0.2?
Any help is greatly appreciated, thanks in advance!
In that case, I would use subsetting:
v[v>2.2 & v<2.6]
or
which(v>2.2 & v<2.6)
depending on if you want the values or the index
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With