0

data.frameクラスのオブジェクトを次のように変換して取得したオブジェクトがrulesありますdata.frame

trx.cpf.rules.df <- as(trx.cpf.rules, "data.frame")

(ここで作成した構造からオブジェクトを構築できますtrx.cpf.rules.df) 。

このデータ フレームの先頭は次のようになります。

> head(trx.cpf.rules.df)
                                                      rules   support confidence     lift
66 {Product_Group_1,Product_Group_49} => {Product_Group_48} 0.1060016  0.7371274 6.683635
12                 {Product_Group_48} => {Product_Group_49} 0.1067810  0.9681979 6.386621
68 {Product_Group_1,Product_Group_23} => {Product_Group_49} 0.1079501  0.9052288 5.971252
16                 {Product_Group_23} => {Product_Group_49} 0.1098987  0.8392857 5.536265
71 {Product_Group_1,Product_Group_23} => {Product_Group_34} 0.1024942  0.8594771 4.702384
19                 {Product_Group_34} => {Product_Group_23} 0.1079501  0.5906183 4.510496

それぞれをrelu;s 要素を含む 2 つのベクトルに変換する高速な方法 (専用関数またはそのようなsth) はありますか? trx.cpf.rules.df$rulesたとえば、最初の行の場合は次のようになります。

> (lhs.el <- c("Product_Group_1", "Product_Group_49"))
[1] "Product_Group_1"  "Product_Group_49"
> (rhs.el <- c("Product_Group_48"))
[1] "Product_Group_48"
4

1 に答える 1

2

これlistにより、lhs/rhs ベクトルを含む構造が得られます。

l <- lapply( strsplit(as.character(trx.cpf.rules.df$rules), " => ", fixed = TRUE), function(x) {
  strsplit(  gsub("[{}]", "", x), ",", fixed = TRUE)
})

最初のルールを調べるには:

l[[1]]
# [[1]]
# [1] "Product_Group_1"  "Product_Group_49"
# 
# [[2]]
# [1] "Product_Group_48"

すべてのルール (head) の左側を調べるには:

head(sapply(l, "[", 1))
# [[1]]
# [1] "Product_Group_1"  "Product_Group_49"
# 
# [[2]]
# [1] "Product_Group_48"
# 
# [[3]]
# [1] "Product_Group_1"  "Product_Group_23"
# 
# [[4]]
# [1] "Product_Group_23"
# 
# [[5]]
# [1] "Product_Group_1"  "Product_Group_23"
# 
# [[6]]
# [1] "Product_Group_34"
于 2015-05-10T10:35:27.877 に答える