Choose Language Hide Translation Bar
Highlighted
jdwatson
Level II

Set cell value if row is selected

Hi,

I'm a newbie trying to write a script to fill in a cell value if its row is selected.  The use case I have in mind is as follow: during exploratory data analysis I select some points in a graph which I suspect to be outliers.  I have another script which helps me look at the raw data (not part of the JMP table), and based on looking at that raw data I decide the row corresponding to this data point should be excluded from my analysis (i.e. the raw data used to generate that particular row is garbage).  I can simply right click and select "Exclude".  Now all my JMP analysis looks at only the good data points which is fine and dandy.  Now after I finish all this analysis I want to go back and do some analysis on the rows that I excluded.  For instance, if each row represents data collected by different operators, maybe one operator is producing a lot of junk data.  I can of course do a point and click solution to select all excluded rows and create a new subset datatable, but what I would prefer to do is add a new column (let's call it FlagColumn) and set all the selected rows in FlagColumn to "bad" and all the other rows to "good".  What I have in mind is something like this:

 

dt = current data table();

rows =  dt << get selected rows ;


For( i=1, 
     i<=5, 
     i++, 
     if(Row State(i) == Selected State(1),
     	dt:FlagColumn[i] = 0
     );
);

But this doesn't seem to do anything - I think I don't understand how to setup the condition in the if statement correctly.  Also, I have not yet figured out how to get the number of rows in the table (so for testing purposes at the moment I just set the index i in the for loop to run from 1 to 5).  Any suggestions?  Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
gzmorgan0
Super User

Re: Set cell value if row is selected

@jdwatson ,

 

Hmmm, to me validating data can be a task that might take more than one editing session.  Also, maybe I'm clumsy, but to me it is so easy to accidentally unselect.  Here is an alternate suggestion that comprehends @Thierry_S  suggestion:

  • if summary/calculated data is deemed poor quality right click and exclude
  • once done validating and run the standard analyses
  • create a new column, I'll call Excluded State.  Make the data type Row State, it has a red star icon. Now you can click on that column name and select Copy From Rowstates see the screen shot below.

rowstateoptions.png

  • Then create a column called Flag or Excluded make it Numeric, Nominal. Make a formula Excluded() and select the button apply, then clear the Formula, press OK. Now you will have a 1 in excluded rows and 0 elsewhere.  
  • Now you can clear the row states and use this  Flag column as planned.  But you have the added benefit to quickly click on the Excluded State column and select Copy to Row States, if you need to do further analyses on the good quality data.

Row State columns are especially nice when there is suspect data or requests for  "what if blah, blah, was removed" analyses.  You can keep a row state for the standard exclusions and the standrd + extra exclusions.  This is a form of row state handling, that is not interactive nor dynamic, but can be quite useful. 

View solution in original post

6 REPLIES 6
Highlighted
txnelson
Super User

Re: Set cell value if row is selected

Look at make rowstste Handler
Jim
Highlighted
Thierry_S
Level VI

Re: Set cell value if row is selected

Hi,
First, it is unclear why you would define "rows = dt << get selected rows" and not use it in the subsequent script.
Second, have you considered the much simpler formula: "Selected ()" which returns 1 if selected and 0 if not (i.e. set the FlagColumn formula as: "Selected ()"). Of note, like all formulas, it is evaluated automatically by default therefore you may need to toggle to Suppress Eval state in the formula dialog to retain a certain state of selection. Also, if you need to only capture the selection state once, you may add the formula, apply the change, and delete the formula which will keep a stable record of what was selected upon running the formula.
Thierry R. Sornasse
Highlighted
Thierry_S
Level VI

Re: Set cell value if row is selected

One more thing,
Have you considered changing the FlagColumn Data Type to "Row State" and use it to capture the current selection state (right click on the column header > Row States Cells > Select/Deselect?
Best,

TS
Thierry R. Sornasse
Highlighted
jdwatson
Level II

Re: Set cell value if row is selected

Ah, yes, this looks like it also accomplishes the same thing I was wanting to do, without any scripting.  It seems that the local data filter doesn't show row state columns, though.  Is there a way to configure a graph window such that it includes excluded rows and then filter using the row state?  Or now that I say this, maybe my real question is what is the simplest way to get a graph/analysis of only the excluded rows without creating separate subset datatables?

Highlighted
jdwatson
Level II

Re: Set cell value if row is selected

I think I answered my own question.  Adding it below in case others come across this problem:

 

dt = current data table();

rs = dt << Get Row States;

For( i=1, 
     i<=Length(rs), 
     i++, 
     if(rs[i] == 1,
     	FlagColumn[i] = 1
     );
);
Highlighted
gzmorgan0
Super User

Re: Set cell value if row is selected

@jdwatson ,

 

Hmmm, to me validating data can be a task that might take more than one editing session.  Also, maybe I'm clumsy, but to me it is so easy to accidentally unselect.  Here is an alternate suggestion that comprehends @Thierry_S  suggestion:

  • if summary/calculated data is deemed poor quality right click and exclude
  • once done validating and run the standard analyses
  • create a new column, I'll call Excluded State.  Make the data type Row State, it has a red star icon. Now you can click on that column name and select Copy From Rowstates see the screen shot below.

rowstateoptions.png

  • Then create a column called Flag or Excluded make it Numeric, Nominal. Make a formula Excluded() and select the button apply, then clear the Formula, press OK. Now you will have a 1 in excluded rows and 0 elsewhere.  
  • Now you can clear the row states and use this  Flag column as planned.  But you have the added benefit to quickly click on the Excluded State column and select Copy to Row States, if you need to do further analyses on the good quality data.

Row State columns are especially nice when there is suspect data or requests for  "what if blah, blah, was removed" analyses.  You can keep a row state for the standard exclusions and the standrd + extra exclusions.  This is a form of row state handling, that is not interactive nor dynamic, but can be quite useful. 

View solution in original post