r - Find indices of numbers of interest in a vector -


i have long vector, let's a <- c(12, 16, 23, 15, 89, 43, ...) , find positions of numbers in vector, contained in vector, b <- c(16, 89).

in example, obtain vector c(2,5). moment using loop, avoid it:

c <- numeric(length(b))  (i in 1:length(c)){       c[i] <- which(a==b[i])   } 

any suggestion? in advance

try

x <- which(a %in% b) #> x #[1] 2 5 

hope helps


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -