Search notes:

R function: which

which(logical_vector) returns the indices of a logical vector that are true:
which(c( F, T, T, F, F, F, T, F, T))
#
#  2 3 7 9
Github repository about-r, path: /functions/which/indices-of-true.R

Find the longest names

The folllowing contrived example finds the longest character-string in a vector:
# find longest name:
names = c('foo', 'bar baz', 'a longer foo than all other bazes', 'bar bazed on his own foo')

names_len = nchar(names)

names[which(names_len == max(names_len))]
# [1] "a longer foo than all other bazes"
Github repository about-r, path: /functions/which/which.R

See also

which.min(…), whcih.max(…)
match(…) returns the index of the first element in a vector that matches a value.
Index to (some) R functions

Index