-2

For eg. I have a vector of different colors,

x = c("blue", "green", "red", "yellow", "green")

I want to find the indices of the elements with value = "green", which in this case would be 2 and 5.

Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32
pwn16wnd
  • 3
  • 1
  • 1
    It is not an `R` list (by syntax) – akrun Sep 07 '21 at 19:52
  • 1
    Does this answer your question? [Is there an R function for finding the index of an element in a vector?](https://stackoverflow.com/questions/5577727/is-there-an-r-function-for-finding-the-index-of-an-element-in-a-vector) – user438383 Sep 07 '21 at 21:28

1 Answers1

-3
> which(x == "green")

[1] 2 5
Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32