closest_to_target | R Documentation |
Get index of element in vector with value closest to a target
closest_to_target(vector, target)
vector |
Identify element in this numeric vector |
target |
numeric target |
an integer indexing vector
closest_to_target(c(0.1, 0.2, 0.3), 0.05) # 1
closest_to_target(c(0.1, 0.2, 0.3), 0.22) # 2
closest_to_target(c(0.1, 0.2, 0.3), -0.05) # 1
closest_to_target(c(0.1, 0.2, 0.3), 8) # 3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.