LoginSignup
4
2

More than 5 years have passed since last update.

アイテムリストが並んでいるだけのデータを0と1の行列に変換する

Posted at
a, b, c
b, c, d
d, e, f

こういうアイテムリストが並んでいるデータを

  a b c d e f
1 1 1 1 0 0 0
2 0 1 1 1 0 0
3 0 0 0 1 1 1

こういう0と1の行列に変換したい。
Rのarulesパッケージを使うと簡単にできるようだ。

require(arules)
tran <- read.transactions("trans.txt", sep=",", format="basket")
mat1 <- as(tran, "matrix")
head(mat1)

参考

http://tjo.hatenablog.com/entry/2014/03/20/190000
http://qiita.com/hidetarou2013@github/items/dc3b448542c5fce7a6ce#matrix_convert

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2