JMP 18:選擇指定列右側的所有列希望選擇位於名為 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 = [];自動化和腳本視窗回覆:JMP 18:選擇指定列右側的所有列我要在這裡做兩處改動。您需要在取得列名訊息中指定「字串」。然後您應該將 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};回覆: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) )
回覆: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." ) )
);回覆:JMP 18:選擇指定列右側的所有列感謝您的修正。
回覆:JMP 18:選擇指定列右側的所有列吉姆:謝謝你的糾正。
回覆:JMP 18:選擇指定列右側的所有列斯科特:感謝您提供有效的程式碼。
回覆:JMP 18:選擇指定列右側的所有列包含 + 使用索引應該會使這變得相當簡單
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);