如何在规则挖掘中将列值分成多个列

时间:2018-05-10 07:41:05

标签: r regex

我有以下数据框,我想将规则列分成不同的列。

数据:

          rules    support  confidence  lift count
5   {32,39,6} => {65}   0.00055 1.00    22.3    12
6   {39,6,65} => {32}   0.00055 0.86    23.4    12
9   {14,16,26} => {4}   0.00051 0.79    8.9     11
13  {16,20,4} => {26}   0.00069 0.71    8.0     15
16  {16,26,33} => {4}   0.00055 0.67    7.6     12
1   {53} => {31}        0.00087 0.66    89.6    19

预期产出:

lhs          rhs 
{32,39,6}   {65}
{39,6,65}   {32}
{14,16,26}  {4}

我尝试过以下代码

rules = sapply(assoc_rules$rules,function(x){
    x = gsub("[\\{\\}]", "", regmatches(x, gregexpr("\\{.*\\}", x))[[1]])
    x = gsub("=>",",",x)
    x = str_replace_all(x," ","")
    return( x )
})

0 个答案:

没有答案