特定の列名が含まれている場合に、列グループの名前を変更するヘルパー関数を作成しています。
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>「アメリカ合衆国[州]」</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));
)
);
);