0

In the following example, there is repeating entries in the second vector. How do I make R to tell me the position of both appearances of 5, please?

 match(5, c(1,2,9,5,3,6,7,4,5))
smci
  • 32,567
  • 20
  • 113
  • 146
LaTeXFan
  • 1,136
  • 4
  • 14
  • 36
  • `which( duplicated(v) | duplicated(v, fromLast=T) )` is a more general solution, and will automatically detect and catch *all* duplicated values, not just a single specific value (e.g. 5) – smci Aug 16 '18 at 23:39

1 Answers1

0

Use the which function:

which(c(1,2,9,5,3,6,7,4,5) == 5)
SmitM
  • 1,366
  • 1
  • 8
  • 14