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
Post a Comment