목록에 포함된 값을 할당합니다.안녕,
이 문제는 정말 난감하네요.
테이블 1(dt_group)의 값을 테이블 2(dt_subset)에 할당하고 싶습니다.
따라서 표 2의 각 행을 반복한 다음 표 2의 Product 열의 행을 표 1의 ProductGroups 의 각 행과 비교한 다음 일치하는 문자열이 발견되면 표 1의 _LIMITS 열에 Limits 값을 할당합니다. 어떻게 스크립트를 작성해야 할까요?
표 1:

표 2:

이미 시도해 보았고 두 테이블의 문자열을 비교하는 데 문제가 있습니다...
Names Default To Here( 1 );
dt_subset = Current Data Table();
col_names = dt_subset << get column names( string );
dt_group = Data Table( "dt_groups" );
aa_limits = Associative Array( dt_group:Tests << get values, dt_group:Limits << get values );
For( i = 1, i <= N Items( aa_limits ), i++,
If( Contains( aa_limits, col_names[i] ),
curname = Column( dt_subset, col_names[i] ) << get name;
new_col = dt_subset << New Column( (curname || "_LIMITS"),
Numeric,
Continuous,
Format( "Percent", 12, 2 )
);
dt_subset << Move Selected Columns( new_col, After( Column( dt_subset, curname ) ) );
)
);
감사해요,
J
자동화 및 스크립팅Re: 목록에 포함된 값 할당짐과 자르모, 고맙습니다!
제가 그것을 알아내는 데 사용한 또 다른 방법은 다음과 같습니다.
Names Default To Here( 1 );
dt_subset = Data Table( "subset table.jmp" );
dt_group = Data Table( "dt_groups.jmp" );
list1 = dt_group:Limits << get values;
list2 = dt_group:ProductGroups << get values;
list3 = dt_group:Tests << get values;
col_names = dt_subset << get column names( string );
aa_limits = Associative Array( dt_group:Tests << get values, dt_group:Limits << get values );
For Each( {val1, idx1}, list2,
For Each Row(
dt_subset,
For Each( {val3, idx2}, list3,
If( Contains( val1, dt_subset:Product ),
As Column( dt_subset, list3[idx1] || "_LIMITS" ) = list1[idx1]
)
)
);
);
Re: 목록에 포함된 값 할당여기 제 시도가 있습니다. 제공된 테이블을 사용하므로 새 열을 만들지 않고 값을 계산하기 위한 공식을 일시적으로 설정합니다(하위 집합 테이블에 미리 생성된 열이 없으면 상당히 간소화될 수 있음)
Names Default To Here(1);
dt_subset = Open("$DOWNLOADS/subset table.jmp");
dt_group = Open("$DOWNLOADS/dt_groups.jmp");
aa_tests = Associative Array();
For Each Row(dt_group,
limitname = :Tests || "_LIMITS";
aa_tests[limitname] = Associative Array();
aa_tests[limitname]["Groups"] = Words(:ProductGroups, " ,");
aa_tests[limitname]["Limit"] = :Limits
);
colnames = dt_subset << Get Column Names("Continuous", "String");
For Each({{testname, specs}}, aa_tests,
If(!Contains(colnames, testname),
Write("\!NNo Match: " || testname);
Continue();
);
Column(dt_subset, testname) << Formula(
If(Contains(specs["Groups"], :Product),
specs["Limit"];
,
.
);
);
dt_subset << run formulas;
Column(dt_subset, testname) << Delete Formula;
);
Re: 목록에 포함된 값 할당완전히 다른 접근 방식이 있습니다. 루프와 비교로 모든 것을 시도하는 대신 JMP의 조인 기능을 사용합니다. 원하는 대로 될 것이라고 생각하지만 결과를 확인해 주세요.
</CODE></PRE>
<PRE><CODE class=" language-jsl">Names Default To Here( 1 );
dt_subset = Data Table( "subset table" );
col_names = dt_subset << get column names( string,continuous );
dt_group = Data Table( "dt_groups" );
// Expand dt_group:ProductGroups into separate columns
dt_group << text to columns( delimiter( "," ), columns( :ProductGroups ) );
// Stack the resulting columns
dt_group_col_names = dt_group << get column names( string );
// Remove the first 3 columns from the list
Remove From( dt_group_col_names, 1, 3 );
// Stack data table
// → Data Table( "Stacked dt_groups" )
dt_stack_group = dt_group << Stack(
columns( dt_group_col_names ),
Source Label Column( "Label" ),
Stacked Data Column( "Product" ),
"Non-stacked columns"n( Keep( :Tests, :Limits ) ),
Output Table( "Stacked dt_groups" )
);
// Get rid of the Label column
dt_stack_group << delete columns( :Label );
// Stack the subset table
// Add a RowNum column to the table to preserve the order
dt_subset << New Column( "RowNum", set each value( Row() ) );
dt_stack_subset = dt_subset << Stack(
columns(
col_names
),
Source Label Column( "Tests" ),
Stacked Data Column( "Data" ),
Name("Non-Stacked columns")(Keep({Product, RowNum})),
Output Table( "Stack of subset table" )
);
// Join the 2 stacked tables
dt_joined = dt_stack_subset << Join(
With( dt_stack_group ),
Merge Same Name Columns,
Match Flag( 0 ),
By Matching Columns( :Product = :Product, :Tests = :Tests ),
Drop multiples( 0, 0 ),
Include Nonmatches( 1, 0 ),
Preserve main table order( 1 ),
Output Table( "Joined stack data" )
);
// Split the table back to original form
dt_final = dt_joined << Split(
Split By( :Tests ),
Split( :Data, :Limits ),
Group( :RowNum ),
Output Table( "Final" ),
Sort by Column Property
);
// Cleanup and rearrange the Final data table
dt_final << delete columns( :RowNum );
// Rename the columns
For( i = 2, i <= N Cols( dt_final ), i++,
theName = Column( dt_final, i ) << get name;
If(
Starts With( theName, "Data" ), Column( dt_final, i ) << set name( Substr( theName, 6 ) ),
Starts With( theName, "Limits" ),
Column( dt_final, i ) << set name( Substr( theName, 8 ) || "_LIMITS" )
);
);
// Reorder the columns
For( i = Length( col_names ), i >= 1, i--,
If( Try( Column( dt_final, col_names[i] || "_LIMITS" ) << get name, "" ) != "",
theName = ":\!"" || col_names[i] || "_LIMITS" || "\!"n";
Eval( Parse( "dt_final << Move Selected Columns( " || theName || ",to first);" ) );
//dt_final << Move Selected Columns( :"Test5^0.8_LIMITS"n,to last)
);
theName = ":\!"" || col_names[i] || "\!"n";
Eval( Parse( "dt_final << Move Selected Columns( " || theName || ",to first);" ) );
);
dt_final << move selected columns( :Product, to first );
close( dt_stack_group, nosave);
close( dt_stack_subset, nosave);
close( dt_joined, nosave);Re: 목록에 포함된 값 할당고맙습니다, 짐! 내가 찾고 있는 것과 정확히 일치하지 않습니다.
예를 들어:
표 2의 제품 열 행 1을 제품 그룹의 첫 번째 행에 있는 모든 문자열과 비교한 다음 해당 제한 값을 할당합니다.

Re: 목록에 포함된 값 할당내가 당신이 지정한 것을 수행하는 방법은 다음과 같습니다.
Names Default To Here( 1 );
dt_subset = Current Data Table();
col_names = dt_subset << get column names( string );
dt_group = Data Table( "dt_groups" );
//aa_limits = Associative Array( dt_group:Tests << get values, dt_group:Limits << get values );
For( i = 1, i <= N Rows( dt_group ), i++,
found = Contains( col_names, dt_group:Tests[i] );
If( found > 0,
//curname = Column( dt_subset, col_names[i] ) << get name;
Eval(
Eval Expr(
new_col = dt_subset << New Column( col_names[found] || "_LIMITS",
Numeric,
Continuous,
Format( "Percent", 12, 2 ),
set each value( Expr( dt_group:limits[i] ) )
)
)
);
dt_subset << Move Selected Columns( new_col, After( Column( dt_subset, col_names[found] ) ) );
)
);
dt_group:tests 열의 이름이 열 이름과 일치하는지 확인하세요. Tests 값과 비교했을 때 열 이름에 여분의 공백이 있을 수 있습니다.