How can find the row indices in one data frame where its values exist in another sorther data frame?

Dear R Users,

I have two data frame. Each of them has three columns but the number of rows is different. I would like to find the row indices of the longer data frame where its values exist in the other data frame. I tried the following:

ind = which(as.numeric(Results[,1]) 
                   %in% as.numeric(Hour.mean[,1]) 
                   & as.numeric(Results[,2]) %in% as.numeric(Hour.mean[,2]) 
                   & as.numeric(Results[,3]) %in% as.numeric(Hour.mean[,3])
)

but it does not give correct values. Could someone suggest me a solution?

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

Meantime I found a solution. I converted the column values of Results and also the Hour.mean with past function and then I could find the row indices with which function with the following way:

List1 = paste(Results[,1], Results[,2], Results[,3], sep=".")
List2 = paste(Hour.mean[,1], Hour.mean[,2], Hour.mean[,3], sep=".")
ind = which(List1 %in% List2)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.