which()
In this page:
which()
which(condition) returns the *indices* where a logical vector is TRUE, rather than the values themselves. This is useful when you need to know the position of matching elements, not just filter them out. which.max() and which.min() are shortcuts for finding the index of the largest/smallest value.
Note: which.max(v) is a shortcut for which(v == max(v))[1], finding the position of the largest value in one call.
Example: which()
v <- c(3, 7, 2, 9, 4)
print(which(v > 4))
cat("Index of max value:", which.max(v), "\n")
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: