안녕하세요 여러분,
내 목표는 각 열에서 가장 일반적인 값(문자 유형)을 갖는 행만 선택하는 것입니다.
예를 들어 내 테이블에는 A, B, C, D라는 네 개의 열이 있습니다. A, B, C, D 열에 가장 많이 나타나는 값은 각각 A1, B2, C3, D4입니다. 이러한 값으로 행을 필터링하고 필터링된 데이터로 새 테이블을 만드는 JSL 코드를 어떻게 작성할 수 있습니까? 감사합니다.
감사해요
(COL -> 최다 출연 횟수)가 A -> A1, B -> B2, C -> C1인 이와 같은 데이터가 있는 경우(실제로 C에 동점이 있는 경우 이를 어떻게 처리해야 합니까?)

A1, B2 및 C1이 있으므로 row1만 유지하시겠습니까? 그리고 동일한 값을 가진 행이 더 있으면 모두 유지하시겠습니까? 아니면 완전히 다른 것을 찾고 계십니까? 예를 들어 가장 많이 나타나는 값만 포함된 테이블을 원하십니까?
문제 해결에 도움이 되는 스크립트는 다음과 같습니다.
Names Default To Here( 1 );
// build an example data table
dt = New Table( "Example",
add rows( 20 ),
New Column( "A",
character,
formula(
rand = Random Uniform( 0, 100 );
If(
rand >= 0 & rand <= 40, x = 1,
rand >= 40 & rand <= 60, x = 2,
rand >= 60 & rand <= 80, x = 3,
x = 4
);
"A" || Char( x );
)
),
New Column( "B",
character,
formula(
rand = Random Uniform( 0, 100 );
If(
rand >= 0 & rand <= 20, x = 1,
rand >= 20 & rand <= 60, x = 2,
rand >= 60 & rand <= 80, x = 3,
x = 4
);
"B" || Char( x );
)
),
New Column( "C",
character,
formula(
rand = Random Uniform( 0, 100 );
If(
rand >= 0 & rand <= 20, x = 1,
rand >= 20 & rand <= 40, x = 2,
rand >= 40 & rand <= 80, x = 3,
x = 4
);
"C" || Char( x );
)
),
New Column( "D",
character,
formula(
rand = Random Uniform( 0, 100 );
If(
rand >= 0 & rand <= 20, x = 1,
rand >= 20 & rand <= 40, x = 2,
rand >= 40 & rand <= 60, x = 3,
x = 4
);
"D" || Char( x );
)
)
);
// The JSL below is the code that does the actual work
Data Table( "Example" ) << Stack(
columns( :A, :B, :C, :D</img> ),
Source Label Column( "Column" ),
Stacked Data Column( "Data" ),
Output Table( "Stacked" )
);
dtS = Data Table( "Stacked" ) << Summary(
Group( :Column, :Data ),
Freq( "None" ),
Weight( "None" ),
output table name( "Summary" )
);
dtS << select where( :N Rows[Row()] == col max(:N Rows, :Data));
dtS << new column("Mode", formula(
Col Max(:N Rows, :Column)
));
dtS << select where( :N Rows == :Mode);
dtS << invert row selection << delete rows;
eval(parse(
"dt << Select Where (dt:\!"" || dts:column[1] || "\!"n == dtS:Data[1] );"));
For( i=2,i<=NRows(dtS), i++,
eval(parse(
"dt << Select Where (dt:\!"" || dts:column[i] || "\!"n == dtS:Data[i] , current selection(\!"extend\!"));"));
);
dtFinal = dt << Subset( selected columns(0), selected rows(1), output table("Final"));