问题描述
假设有两个字符,A
和 B
:
A <- c("A","B",NA,"D2","K")
B <- c("A","C","D1","E","F","K","L")
虽然 B
只包含唯一条目,但 A
中的元素不必是唯一的。
现在我想获取 A
中元素的索引,因为它们出现在 B
中,NA
除外。因此,在上面的例子中,R 函数应该返回
1 2 2 5 8
非常感谢!
解决方法
我们可以使用C:\Users\Hp\Desktop\django-calculator>python manage.py runserver
python: can't open file 'C:\Users\Hp\Desktop\django-calculator\manage.py': [Errno 2] No such file or directory
match
,
这是另一个使用命名向量的基本 R 选项
> na.omit(setNames(seq_along(B),B)[A])
A B B D2 K
1 2 2 5 8
attr(,"na.action")
<NA>
4
attr(,"class")
[1] "omit"