本文へスキップ
からだにいいもの

Rのトピックスを中心に『まだ、まだ、知らない、役に立つ情報?』を発信します。

Rで解析:重複?共通?集合演算コマンドについて

集合演算を扱うコマンドの紹介です。データの共通や差を判断するのに有効です。sort()などで結果を並び替えると良いかもしれません。

コマンド一覧

#データ例の作成
x <- c(4, 7, 8, 3, 11, 15)
y <- c(1, 2, 5, 3, 11, 16)

#和集合
union(x, y)
[1]  4  7  8  3 11 15  1  2  5 16

#積集合、共通
intersect(x, y)
[1]  3 11

#差集合
setdiff(x, y)
[1]  4  7  8 15

少しでも、あなたの解析が楽になりますように!!

スポンサーリンク
Prices and shipping availability may change. Please refer to the product page at time of purchase.
Content displayed on this site is provided by Amazon and may be updated or removed.
Amazon Associate, karada-good earns income through qualifying sales.