JMP 18: 指定した列の右側にあるすべての列を選択するAdders という列の右側にあるすべての列を選択しようとしています。以下のコードは実行されますが、Adders の右側にある列は視覚的に選択されません。Adders の左側と右側にある列の数は異なる場合があります。
<JSL> Names Default To Here(1);
dt = Data Table("Test Table");
dt << Bring Window To Front;
Show(dt << Get Name);
// Step 1: Get all column names and show them
colNames = dt << Get Column Names();
Show(colNames);
// Step 2: Find the index of the "Adders" column
targetColName = "Adders";
colIndex = Loc(colNames, targetColName);
Show(colIndex); // Should be > 0 if found
// Step 3: Try to visually select all columns to the right
If(colIndex > 0 & colIndex < N Cols(dt),
dt << Clear Column Selection;
For(i = colIndex + 1, i <= N Cols(dt), i++,
Column(dt, i) << Set Selected(1);
);
// Step 4: Show what JMP thinks is selected
selected = dt << Get Selected Columns;
Show(selected);
,
New Window("Error", Text Box("Column 'Adders' not found, or it's the last column."));
);</JSL>
出力:
dt << Get Name = "Test Table";
colNames = {A, B, Adders, X, Y};
colIndex = [];自動化とスクリプトウィンドウズRe: JMP 18: 指定した列の右側にあるすべての列を選択するここで 2 つの変更を行います。Get Column Names メッセージで「文字列」を指定する必要があります。次に、Loc() 関数を Contains() に変更する必要があります。Loc() はマトリックスを返しますが、空の場合もあります。Contains() は整数 (見つからない場合は 0) を返します。
Names Default To Here(1);
dt = Data Table("Test Table");
dt << Bring Window To Front;
Show(dt << Get Name);
// Step 1: Get all column names and show them
colNames = dt << Get Column Names( "string" );
Show(colNames);
// Step 2: Find the index of the "Adders" column
targetColName = "Adders";
colIndex = Contains(colNames, targetColName);
Show(colIndex); // Should be > 0 if found
// Step 3: Try to visually select all columns to the right
If(colIndex > 0 & colIndex < N Cols(dt),
dt << Clear Column Selection;
For(i = colIndex + 1, i <= N Cols(dt), i++,
Column(dt, i) << Set Selected(1);
);
// Step 4: Show what JMP thinks is selected
selected = dt << Get Selected Columns;
Show(selected);
,
New Window("Error", Text Box("Column 'Adders' not found, or it's the last column."));
);
//Output:
//dt << Get Name = "Test Table";
//colNames = {"A", "B", "Adders", "X", "Y"};
//colIndex = 3;<BR />//selected = {:X, :Y};Re: JMP 18: 指定した列の右側にあるすべての列を選択する他にもこれを行う方法はあると思いますが、次のスクリプトは「Adders」列を見つけて、その列と右側のすべての列を選択します。
names default to here(1);
dt = current data table();
targetCol = "Adders";
targetColNum = 0;
for( i = 1, i <= n cols( dt ), i++,
if( column( dt,i ) << get name == targetCol, targetColNum = i )
);
dt << select columns( targetColNum::n cols(dt) )
Re: JMP 18: 指定した列の右側にあるすべての列を選択する最初の投稿を編集し、編集入力ウィンドウの上部にある入力アイコンを使用して、JSL とその出力をそれぞれ JSL ウィンドウとコード ウィンドウに移動しました。
また、コードを変更して、<< が列名を取得し、文字列を返し、Loc() を使用する代わりに Contains() を使用して、マトリックス値ではなく単一の値を返すようにしました。
Names Default To Here(1);
dt = Data Table("Test Table");
dt << Bring Window To Front;
Show(dt << Get Name);
// Step 1: Get all column names and show them
colNames = dt << Get Column Names(string);
Show(colNames);
// Step 2: Find the index of the "Adders" column
targetColName = "Adders";
// Loc() returns a matrix, contains returns a scaler value
colIndex = contains(colNames, targetColName );
Show( colIndex ); // Should be > 0 if found
// Step 3: Try to visually select all columns to the right
If( colIndex > 0 & colIndex < N Cols( dt ),
dt << Clear Column Selection;
For( i = colIndex + 1, i <= N Cols( dt ), i++,
Column( dt, i ) << Set Selected( 1 )
);
// Step 4: Show what JMP thinks is selected
selected = dt << Get Selected Columns;
Show( selected );
,
New Window( "Error", Text Box( "Column 'Adders' not found, or it's the last column." ) )
);Re: JMP 18: 指定した列の右側にあるすべての列を選択する訂正ありがとうございます。
Re: JMP 18: 指定した列の右側にあるすべての列を選択するジム: 訂正していただきありがとうございます。
Re: JMP 18: 指定した列の右側にあるすべての列を選択するスコット: 動作するコードをありがとうございます。
Re: JMP 18: 指定した列の右側にあるすべての列を選択するContains + インデックスを使用すると、これはかなり簡単になります
Names Default To Here(1);
dt = Data Table("Test Table");
collist = dt << Get Column Names("String");
adders_idx = Contains(collist, "Adders");
If(adders_idx == 0,
Throw("No Adders column found");
);
dt << Select columns(collist[adders_idx + 1::N Items(collist)]);
Show(dt << Get Selected Columns);