(x <- c(sort(sample(1:20, 9)),NA)) (y <- c(sort(sample(3:23, 7)),NA)) union(x, y) intersect(x, y) setdiff(x, y) setdiff(y, x) setequal(x, y)
結果
> (x <- c(sort(sample(1:20, 9)),NA)) [1] 3 4 6 9 11 12 14 18 19 NA > (y <- c(sort(sample(3:23, 7)),NA)) [1] 7 8 15 17 18 20 22 NA > union(x, y) [1] 3 4 6 9 11 12 14 18 19 NA 7 8 15 17 20 22 > intersect(x, y) [1] 18 NA > setdiff(x, y) [1] 3 4 6 9 11 12 14 19 > setdiff(y, x) [1] 7 8 15 17 20 22 > setequal(x, y) [1] FALSE