将数据从列转到行。

时间:2021-09-25 15:33:09

I am planning to work on "High-Utility Item set mining" via java based SPMF tool. But the issue is getting the data into right format before load the data into SPMF.

我计划通过基于java的SPMF工具进行“高效用项集挖掘”。但是问题是在将数据加载到SPMF之前,要将数据转换成正确的格式。

My current format:

我现在的格式:

 Transaction #  Item    Amount

        1001    200 14
        1001    201 13
        1001    202 16
        1001    205 17
        1002    300 11
        1002    305 12
        1002    200 30

Desired output: (No transaction number needed, each transaction is one line)

期望输出:(不需要事务号,每个事务是一行)

200 201 202 205:60:14 13 16 17
300 305 200:53:11 12 30 

Explanation for desired output:

解释需要的输出:

200 201 202 205 --->   are Items (left of 1st row)
14 13 16 17      --->  are Amount (right of first row)
:60:          ---->    is total amount of transaction # 1001 (14+13+16+17)

I am open to any solution. I can load my current format into SQL and extract the data via SQL query if I get right query to achieve my output. Please help.

我愿意接受任何解决办法。如果得到正确的查询,可以将当前格式加载到SQL中,并通过SQL查询提取数据以实现输出。请帮助。

1 个解决方案

#1


4  

Using by for example :

例如:

by(dx,dx$Transaction,function(x)c(x$Item,sum(x$Amount),x$Amount))

dx$Transaction: 1001
[1] 200 201 202 205  60  14  13  16  17
------------------------------------------------------------------------------- 
dx$Transaction: 1002
[1] 300 305 200  53  11  12  30

#1


4  

Using by for example :

例如:

by(dx,dx$Transaction,function(x)c(x$Item,sum(x$Amount),x$Amount))

dx$Transaction: 1001
[1] 200 201 202 205  60  14  13  16  17
------------------------------------------------------------------------------- 
dx$Transaction: 1002
[1] 300 305 200  53  11  12  30