apply - intersection in R -
apply - intersection in R -
i have 2 tables.
both tables have 1 column.
both have random integer values between 1 1000.
i want intersect these 2 tables. grab want intersect numbers if have difference of 10.
1st table -> 5 , 50, 160, 280 2nd table -> 14, 75, 162, 360
output ->
1st table -> 5, 160 2nd table -> 14, 162
how can accomplish in r
you sapply
function, checking if each element of x
or y
sufficiently close fellow member of other vector:
x <- c(5, 50, 160, 280) y <- c(14, 75, 162, 360) new.x <- x[sapply(x, function(z) min(abs(z-y)) <= 10)] new.y <- y[sapply(y, function(z) min(abs(z-x)) <= 10)] new.x # [1] 5 160 new.y # [1] 14 162
r apply
Comments
Post a Comment