합집합,교집합,차집합 in r

Published by onesixx on

R

2 vector

A <- c(1,2,3,4,5)
B <-       c(4,5,6,7,8)

합집합 (A∪B)

> unique(c(A,B))
[1] 1 2 3 4 5 6 7 8

교집합(A∩B)

> A[A%in%B]
> B[B%in%A]

> intersect(A,B)
[1] 4 5

차집합(A-B)

> A[!(A%in%B)]
[1] 1 2 3

Multi-vector

https://www.r-bloggers.com/intersect-for-multiple-vectors-in-r/

Reduce(intersect, list(a,b,c))

Reduce(union, list(x, y, z))

reduce()
combine from the left

R

Categories: Reshaping

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x