R - Find() and Position() give the first or last element and its position in the vector that gives true for the logical function

14 Aug 2019

Find() returns the actual value (1st element only; use right=TRUE to retrieve the last)

Position() returns its index

mylist3 <- c(runif(5))
mylist3
# [1] 0.8825526 0.8386051 0.8569615 0.5358881 0.2192216

Find(function(x) x>0.6, mylist3)
# [1] 0.8825526
Find(function(x) x>0.6, mylist3, right=TRUE)
# [1] 0.8569615


Position(function(x) x>0.6, mylist3)
# [1] 1
Position(function(x) x>0.6, mylist3, right=TRUE)
# [1] 3
[ R  function  vector  ]