특정 열 이름을 포함하는 열 그룹의 이름을 변경하는 헬퍼 함수를 작성하고 있습니다.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
/*//Use if already existing
dt = Data Table ("Cities");
*/
dt << group columns( "xy", {:X, :y} );
dt << group columns( "pollutants", :Ozone :: :Lead );
match_col = "X";
new_name = "coordinates";
groups_list = dt << get column groups names;
show(groups_list);
For Each({grp, ig}, groups_list,
cols = dt << get column group( grp );
show(cols);
For Each ({column, ic}, cols,
show(column);
colname = column << Get Name;
If(colname == match_col,
try(dt << rename column group( grp, new_name );)
)
);
);
이 방법은 기본적인 그룹화된 열에서는 잘 작동하지만, 링크 참조에서 상속된 그룹이 있는 경우에는 오류가 발생합니다.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
dt_state = Open( "$SAMPLE_DATA/State Abbreviations.jmp" );
//Need more than 1 column
dt_state << New Column( "Dummy", Numeric, "Continuous", Format( "Best", 12 ));
//Link Tables
dt_state:Abbreviations << Set Property( "Link ID", 1 );
dt:State << Set Property("Link Reference", Reference Table(dt_state));
/*//Use if already existing
dt = Data Table ("Cities");
dt_state = Data Table( "State Abbreviations" );
*/
dt << group columns( "xy", {:X, :y} );
dt << group columns( "pollutants", :Ozone :: :Lead );
match_col = "X";
new_name = "coordinates";
groups_list = dt << get column groups names;
show(groups_list);
For Each({grp, ig}, groups_list,
cols = dt << get column group( grp );
show(cols);
For Each ({column, ic}, cols,
show(column);
colname = column << Get Name;
If(colname == match_col,
try(dt << rename column group( grp, new_name );)
)
);
);
Firstly, the << Get Name function errors on :Ozone, which worked fine in the simpler example.
해당 오류가 해결되더라도 로그에서 연결된 열의 모양은 다르게 나타납니다.
column = :Y;
column = Referenced Column(<STRONG>"미국 주[State]"</STRONG>, Reference(Column(:State), Reference(Column(:U.S. States))));
텍스트 이름(예: "미국 주[주]") 을 어떻게 추출하나요?
JMP가 잘못된 데이터 테이블을 참조하고 있어서 문제가 발생하는 것 같습니다. 제 생각에는 항상 명시적인 열 참조를 사용하는 것이 좋습니다. 즉, 열(참조)을 항상 문자열로 변환한 다음 필요에 따라 다른 형식을 사용하세요. 예를 들어 다음과 같이 하면 됩니다.
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Cities.jmp");
dt_state = Open("$SAMPLE_DATA/State Abbreviations.jmp");
dt_state << New Column("Dummy", Numeric, "Continuous", Format("Best", 12));
dt_state:Abbreviations << Set Property("Link ID", 1);
dt:State << Set Property("Link Reference", Reference Table(dt_state));
dt << group columns("xy", {:X, :y});
dt << group columns("pollutants", :Ozone :: :Lead);
match_col = "X";
new_name = "coordinates";
groups_list = dt << get column groups names;
For Each({grp, ig}, groups_list,
cols = Transform Each({colweirdness}, dt << get column group(grp), AsColumn(dt, colweirdness) << get name);
For Each({colname, ic}, cols,
If(colname == match_col,
try(dt << rename column group(grp, new_name));
)
);
);