assign value after/before currently selected rowsHello, out of curiosity,
if you have selected rows but need to select not only these ones but also the ones exactly adjacent (before/after, 1 row respectively), how can you script this?
I now did it with creating several new columns and adding values to the rows I would like to also select to be able to later run a Select Where function.
A more elegant way would be highly appreciated!
Cheers, Astrid
Re: assign value after/before currently selected rowsThanks, this one worked perfectly for my question!
@julian wrote:
Hi Astrid,
I suspect there is a more elegant way, but the following should do it:
dt = Current Data Table();
curSelRow = as list(dt << Get Selected Rows());
newSelRow = curSelRow || curSelRow + 1 || curSelRow - 1;
//remove a row = 0 reference if present
Remove From( newSelRow, aslist(loc(newSelRow,0)));
//remove reference to a row beyond data set
Remove From( newSelRow, aslist(loc(newSelRow,NRows(dt)+1)));
dt << Select Rows(newSelRow);
edit: added code to remove reference to a row after the last row in the data set (which would happen if the last row in the data set is selected)
@julian wrote:
Hi Astrid,
I suspect there is a more elegant way, but the following should do it:
dt = Current Data Table();
curSelRow = as list(dt << Get Selected Rows());
newSelRow = curSelRow || curSelRow + 1 || curSelRow - 1;
//remove a row = 0 reference if present
Remove From( newSelRow, aslist(loc(newSelRow,0)));
//remove reference to a row beyond data set
Remove From( newSelRow, aslist(loc(newSelRow,NRows(dt)+1)));
dt << Select Rows(newSelRow);
edit: added code to remove reference to a row after the last row in the data set (which would happen if the last row in the data set is selected)
Re: assign value after/before currently selected rowsThanks, it worked!
Re: assign value after/before currently selected rowsdt = Open( "$SAMPLE_DATA/Cities.jmp" );
dt << Select Randomly(0.1); // Select random rows for demo
SR = dt << Get Selected Rows(); // Get row numbers of selected rows
// Assuming we want to select the rows after the selected rows
for( i = 1, i <= N Row(SR), i++,
NewRowToSelect = SR[i] + 1 ;
dt << Select Rows(NewRowToSelect); // Alternatively can store these values as a list and pass at once
);
Re: assign value after/before currently selected rowsHi Astrid,
I suspect there is a more elegant way, but the following should do it:
dt = Current Data Table();
curSelRow = as list(dt << Get Selected Rows());
newSelRow = curSelRow || curSelRow + 1 || curSelRow - 1;
//remove a row = 0 reference if present
Remove From( newSelRow, aslist(loc(newSelRow,0)));
//remove reference to a row beyond data set
Remove From( newSelRow, aslist(loc(newSelRow,NRows(dt)+1)));
dt << Select Rows(newSelRow);
edit: added code to remove reference to a row after the last row in the data set (which would happen if the last row in the data set is selected)