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 ) || ">=" )
)
);