여러분, 안녕하세요,
여러 열이 있습니다.
1- "시작일" 열
2- '종료일' 열
일반적으로 그룹 (2)에 속하는 각 열은 그룹 (1)에도 속해야 하며 그 반대의 경우도 마찬가지입니다. 따라서 두 그룹에 같은 수의 열이 있어야 합니다.
그러나 그룹 1에 속한 열은 그룹 2에 속하지 않으며 그 반대도 마찬가지입니다.
예 : "시작 날짜 9899"이지만 "종료 날짜 9899" 열이 없습니다.
목표는 두 그룹에 동일한 열이 있도록 이 두 그룹의 교차점을 갖는 것입니다.
다음 코드에서 영감을 받았습니다.Names Default To Here(1);
dt = Current Data Table();
// build
aa_duree = Associative Array();
aa_nonduree = Associative Array();
For Each({col_name}, dt << Get Column Names("String"),
If(Word(1, col_name) == "date début",
aa_duree[Word(-1, col_name)] = col_name;
, !IsMissing(Regex(col_name, "")),
aa_nonduree[col_name] = 1;
,
continue()
);
);
show(aa_duree);
show(aa_nonduree);
aa_duree_copy = aa_duree;
aa_duree_copy << Intersect(aa_nonduree);
cols_to_keep = Insert(aa_duree_copy << get keys, aa_duree_copy << get values);
aa_duree_copy2 = aa_duree;
aa_nonduree_copy = aa_nonduree;
aa_duree_copy2 << remove(aa_nonduree);
aa_nonduree_copy << remove(aa_duree);
cols_to_remove = Insert(aa_nonduree_copy << get keys, aa_duree_copy2 << get values);
show(cols_to_keep, cols_to_remove); 제공된 예제 스크립트는 Word(1, col_name)가 문자열의 첫 번째 작업만 반환하고 두 단어와 비교하기 때문에 작동하지 않습니다. 따라서 if 문은 항상 else 문으로 이동합니다. 다른 문제가 있을 수 있지만 적어도 하나의 문제가 있습니다. 예를 들어 단어를 Starts With()로 변경해 볼 수 있습니다. https://www.jmp.com/support/help/en/17.0/#page/jmp/character-functions-2.shtml?os=win&source=application#ww2489516 . 또한 문자열을 비교할 때 대소문자가 올바른지 확인하십시오.
문제를 공격하는 나의 구식 방법은 다음과 같습니다.
Names Default To Here( 1 );
dt = Current Data Table();
keep = {};
delete = {};
colNameList = dt << get column names( string );
For Each( {col, i}, colNameList, colNameList[i] = Uppercase( col ) );
While( N Items( colNameList ) > 0,
If(
Contains( colNameList[1], Uppercase( "Date début" ) ),
found = Contains( colNameList, Substitute( colNameList[1], Uppercase( "début" ), "FIN" ) );
If( found > 0,
Insert Into( keep, colNameList[1] );
Insert Into( keep, colNameList[found] );
Remove From( colNameList, found, 1 );
Remove From( colNameList, 1, 1 );
,
Insert Into( delete, colNameList[1] );
Remove From( colNameList, 1, 1 )
);,
Contains( colNameList[1], Uppercase( "Date fin" ) ),
found = Contains( colNameList, Substitute( colNameList[1], "FIN", Uppercase( "début" ) ) );
If( found > 0,
Insert Into( keep, colNameList[1] );
Insert Into( keep, colNameList[found] );
Remove From( colNameList, found, 1 );
Remove From( colNameList, 1, 1 );
,
Insert Into( delete, colNameList[1] );
Remove From( colNameList, 1, 1 )
);,
Remove From( colNameList, 1, 1 )
)
);
show( keep, delete );