【发布时间】:2012-08-01 17:35:06
【问题描述】:
假设我有两列 x = c("a", "c", "g") 和 y = c("a", "b", "c", "d", "e", "f", "g")。
x 是dataframe1 中的一列,y 是dataframe 2 中的一列。dataframe1 在维度上不一定匹配dataframe 2。
我想返回包含 x 的 y 行。例如,我想得到 1、3、7。
我尝试了类似items = which(dataframe1$x == dataframe2$y) 这样的笨拙方法,但显然这不起作用。我知道我可以循环遍历dataframe1$x 并将其与dataframe2$y 匹配,但似乎应该有更好的解决方案。
【问题讨论】:
标签: r indexing dataframe match