我有一个这样的表:
| 清单 | 苹果红 | 苹果黄 | 香蕉红 | 香蕉黄 |
| 一种 | 1 | 11 | 21 | 31 |
| b | 2 | 12 | 22 | 32 |
| C | 3 | 13 | 23 | 33 |
我想使用多个系列(这里是苹果和香蕉)来堆叠数据,但是所有系列(这里是红色和黄色)只需要1个标签。输出如下:
| 清单 | 苹果 | 香蕉 | 组 |
| 一种 | 1 | 21 | 红色 |
| 一种 | 11 | 31 | 黄色 |
| b | 2 | 22 | 红色 |
| b | 12 | 32 | 黄色 |
| C | 3 | 23 | 红色 |
| C | 13 | 33 | 黄色 |
我尝试了堆栈函数,但我认为这需要一些特殊的脚本。非常感谢!
无需脚本即可完成三个操作。
一,使用表格->堆栈堆叠四列( 苹果红,苹果黄,香蕉红,香蕉黄 )放入一列中。
您将得到以下结果:

现在,使用 Cols-> Ultities->文本到列将水果与“标签”列中的颜色分开。在定界符字段中放置一个空格。

您将获得两个新列。重命名他们水果和颜色 。您可以删除标签柱。

现在使用表格->拆分分割数据列水果。

现在,您将获得所需的数据表,苹果列和香蕉柱。

如果您堆叠数据,然后为“水果”创建一个新列,为“颜色”创建另一个列,则可以将数据拆分为所需的数据表。
下面的脚本说明了如何完成此操作。 但是,交互式地执行这些步骤是我构建脚本的方式,因此您可以轻松地重复交互式步骤。
Names Default To Here( 1 );
// Create the sample data table
dt = New Table( "Example",
Add Rows( 3 ),
New Script(
"Source",
Data Table( "Untitled 67" ) << Split(
Split By( :Column 2 ),
Split( :Column 1 ),
Sort by Column Property
)
),
New Column( "List", Character, "Nominal", Set Values( {"a", "b", "c"} ) ),
New Column( "Apple red", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3] ) ),
New Column( "Apple yellow", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11, 12, 13] ) ),
New Column( "Banana red", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [21, 22, 23] ) ),
New Column( "Banana yellow", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [31, 32, 33] ) )
);
// Stack the columns
dtStack = dt << Stack(
columns( :Apple red, :Apple yellow, :Banana yellow, :Banana red ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" )
);
// Create 2 New Columns separating the fruit from the color
dtStack << New Column("Fruit", character, formula(word(1,:Label," ")));
dtStack << New Column("Color", character, formula(word(2,:Label," ")));
// Split the data back into the required new columns
dtFinal = dtStack << Split(
Split By( :Fruit ),
Split( :Data ),
Remaining Columns( Drop( :Label ) ),
Sort by Column Property
);
