R语言中IF可以用来反复取向量的变量并使用which函数吗?

x <- mydataframe1[,2]

y <- mydataframe2[,2]

 

x[1]

nrow_dataframe2 <- which(y==x[1])

mydataframe4 <- mydataframe2[nrow_dataframe2,]

mydataframe <- rbind.data.frame(mydataframe,mydataframe4)

这个是可以 的

 

我是想这样写的:

if i in 1:nrow(mydataframe1)

x[i]

nrow_dataframe2 <- which(y==x[i])

mydataframe4 <- mydataframe2[nrow_dataframe2,]

mydataframe <- rbind.data.frame(mydataframe,mydataframe4)

 

但是不行

...

所以能不能通过IF把x中所有的对象都执行这个循环体?或者其他方法把y中x的所有变量及位置都找到。因为我是想通过位置再确定行数,然后提取mydataframe2中的符合mydataframe1的行。

已知:

mydataframe1是mydataframe2的子集;

x中所有的变量在y中都出现不止一次。

 

直接用match的话也不行,只能一共只能返回10个值。

 

新手小白,无编程专业知识。因为不想用excel表反复操作,想通过代码实现这样一对多的匹配。求大佬指导,不胜感激。

 

你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答

本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。

​​​​因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。