使用列表中的列名稱創建列公式你好,
我有一個簡單的腳本,我想在其中創建一個新列,其中公式計算另一列的絕對值。
該列在列表中被引用。
我嘗試了幾種不同的方法,但我不知道如何評估引用的列,因此我最終得到一個空的公式列。 任何建議將不勝感激。
最好的
塞巴斯蒂安
dt=New Table( "test",
Add Rows( 4 ),
New Column( "symbol",
Character,
"Nominal",
Set Values( {"a", "b", "c", "d"} ),
Set Display Width( 55 )
),
New Column( "fold change",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [-3, -0.4, 0.4, 3] ),
Set Display Width( 68 )
)
);
l={"fold change"};
try(New Column( "absolute fold change",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Abs( l[1] )
)));
try(New Column( "absolute fold change 2",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( eval(column(l[1]) )
)));
質量和工藝工程回复:使用列表中的列名稱創建列公式沒問題。 昨天我遇到了同樣的問題,我花了一段時間才弄清楚。
實際上我也剛剛了解到另一種解決方案。
“As Column()”函數將返回指定為參數的列中當前行的值。
因此該公式同樣可以採用如下格式:
公式(
Abs( 作為列( l[1] ) );
);
很簡約!回复:使用列表中的列名稱創建列公式非常感謝,我嘗試了您提出的選項,但有一個很大的區別:沒有空括號。
最好的,
塞巴斯蒂安回复:使用列表中的列名稱創建列公式dt=New Table( "test",
Add Rows( 4 ),
New Column( "symbol",
Character,
"Nominal",
Set Values( {"a", "b", "c", "d"} ),
Set Display Width( 55 )
),
New Column( "fold change",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [-3, -0.4, 0.4, 3] ),
Set Display Width( 68 )
)
);
l = {"fold change"};
try(New Column( "absolute fold change",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Abs( column( l[1] )[] )
)));由於您的列表僅包含字符串,因此您需要使用 Column( "" )[ ] 函數告訴 JMP 該字符串是列名。
空白方括號是必要的,如果沒有它們,公式將引用整列而不僅僅是適當的行。
希望這有幫助,
萊因