I have two matrices, a is 3000 by 3, b is 1000 by 3. Each row of a or b (e.g. a[,221]) is a 3-vector. I would like to find the row index of a which contains the common rows between a and b. Could you please help? I did a %in% b but seems not right. Thanks.
CodePudding user response:
match(do.call(paste, data.frame(a)), do.call(paste, data.frame(b)))
or even:
A <- data.frame(a)
B <- cbind(id = seq(nrow(b)), setNames(data.frame(b), names(A)))
merge(A, B, all.x = TRUE)