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,
a
a <- c("bob","jim","joe","fred")
我有另一个字符向量b,具有相同的元素但顺序不同,
b
b <- c("joe", "jim", "fred", "bob")
是否有一个函数可以告诉a每个元素的哪个元素b等于?换句话说,我想要一个可以返回的函数c(3,2,4,1)(因为b相当于 c(a[3], a[2], a[4], a[1]). 谢谢!
c(3,2,4,1)
c(a[3], a[2], a[4], a[1])
你正在寻找match(b, a).
match(b, a)