Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两个长度不等的向量,a 和 b,长度(a)小于 b。
我想在“a”中找到包含相交(a,b)中的值的索引。我怎样才能做到这一点?
就像是
a <- list(1,2,3,4,5) b <- list(6,2,1,5,7,9,10)
并且您想确定 in 元素的位置a,请b使用:
a
b
which(a %in% b) # [1] 1 2 5
a如果和b是向量,这也有效,例如a <- c(1,2,3,4,5)和b <- c(6,2,1,5,7,9,10)
a <- c(1,2,3,4,5)
b <- c(6,2,1,5,7,9,10)