Intersection of rows

Hi. I would like a vector showing the number of intersections of each row of a and b, but I can't quite get it to work. Thank you.

z <- vector()
a <- data.frame(rbind(x=c(1,6,7), y=c(1,2,8), z=c(1,2,3)))
b <- data.frame(rbind(x=c(1,5,7,8,9,10), y=c(1,2,7,8,9,10), z=c(1,2,3,8,9,10)))

inc <- function(x, y) length(intersect(a, b))
z <- inc(a,b)

You can do:

vapply(1L:nrow(a), function(i) {
  length(intersect(a[i, ], b[i, ]))
}, FUN.VALUE = integer(1L))