dt = Current Data Table();
// List of column names for the table
col_names = dt << get column names( string );
// Create cumulative sum of each D
looking_for_channel_1 = "D";
For( i = 1, i <= N Items( col_names ), i++,
// search column names for "D"
If( Starts With( col_names[i], looking_for_channel_1 ),
new_col = dt << New Column( Char( col_names[i] ) || ">=",
Numeric,
.................................
);
);
);
親愛なるみんな、
私は現在の問題を解決しようとしている新しいスクリプト作成者です。 構文にはあまり詳しくありませんが、列と行をループして各ツールと行の累計を計算し、結果を新しい列に保存したいと考えています。 解決策を示すデータ表を添付しました。
フィードバックをお寄せいただきありがとうございます。
BR
マーティン
これは別のアプローチです。数式列を使用して新しい列を作成するだけです。
Names Default To Here( 1 );
// This JSL assume the table contains only the Tool column,
// followed by the Dnnn columns. No cummulative columns have been
// created yet
dt = Current Data Table();
totCol = N Cols( dt );
// Loop across the columns creating the new cumulative sums
For( i = 2, i <= totCol, i++,
Eval(
Substitute(
Expr(
dt << New Column( __newname__, formula( __formula__ ) )
),
Expr( __newname__ ), Column( dt, i ) << get name || ">=",
Expr( __formula__ ),
If( i == 2,
Parse( Column( dt, i ) << get name ),
Parse(
"sum( :Name(\!"" || char( Column( dt, i - 1 ) << get name ) || ">=\!"), " || char( Column( dt, i ) << get name )
|| ")"
)
)
)
)
);私はあなたの問題を解決するために別のアプローチをとりました。データをループし、提案どおりにデータを蓄積すると、列と行が多くなると非常に遅くなります。組み込みの JMP 関数を使用すると、はるかに高速になります。以下は、組み込みの Col Cumulative Sum() 関数を使用してデータをトール データ テーブルに転置して処理を実行し、処理が完了した後にデータをワイド フォーマットに転置するスクリプトです。
names default to here(1);
dt=current data table();
// Transform the data into a long table from the current wide table
// to allow for faster processing using the built in column function
// col cumulative sum()
dtStack = dt << Stack(
columns( :D300, :D200, :D100, :D50, :D10 ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Name( "Non-stacked columns" )(Keep( :Tool, :Column 13 ))
);
// Add a new column to insure an alphbetical ordering of the original
// data table
dtStack << New Column( "Row Number",
Character,
"Nominal",
Formula(
If( Lag( :Tool ) != :Tool,
counter = 0
);
counter = counter + 1;
result = Substr( "00", Length( Char( counter ) ) - 3 ) || Char( counter )
|| " " || :Label;
)
);
// Add the Cumulative Sum column
dtStack << New Column( "xx",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Col Cumulative Sum( :Data, :Tool ) ),
Set Selected
);
// Transpose the data back into a wide format
dtFinal = dtStack << Split(
Split By( :Row Number ),
Split( :Data, :Name( "xx" ) ),
Group( :Tool ),
Remaining Columns( Drop All ),
Sort by Column Property
);
// Close the nolonger needed stack data table
close(dtStack,nosave);
// Pass across the column names adjusting them back to the desired form
For( i = 2, i <= N Cols( dtFinal ), i++,
If(
Word( 1, Column( dtFinal, i ) << get name, " " ) == "Data",
Column( dtFinal, i ) << set name( Substr( Column( dtFinal, i ) << get name, 10 ) )
,
Word( 1, Column( dtFinal, i ) << get name, " " ) == "xx",
Column( dtFinal, i ) << set name( Substr( Column( dtFinal, i ) << get name, 8 ) || ">=" )
)
);