Get index of a specific element in vector using %>% operator

Viewed 12328

I want the index of an element in a vector x

x <- c("apple", "banana", "peach", "cherry")

With base R i would do that

which(x == "peach")

But as my x is at the end of a pipe I would like to get the index the magrittr way.

x %>% getIndex("peach")

My desired output is 3.

2 Answers
Related