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 = [];自动化和脚本视窗回复: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);