cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Stats_Like_Jazz
Level III

Making Subsets Smarter - Help Needed

Hi Hive Mind,

 

I quite often make a subset of my data table.

 

My current method is

  1. Find a value that is representative of my subset
  2. Right click -> Select matching cells
  3. Tables -> Subset à selected rows, all columns
  4. Save file

Alternatively, I will

  1. Use “Save as” to create a new file
  2. Find a value that is representative of my subset
  3. Right click -> Select matching cells
  4. Invert selection
  5. Delete Rows

 

I do this many times on a weekly basis… and it is painful…

 

So here is my idea that I need help with:

 

I want to create a script that when I have selected my matching cells I can click a button that will make a subset of the selected rows:

 

Here is my best shot so far (it doesn’t work)

 

Dt = current data set();

My_list = dt << Get Selected();

Dt << Subset(

                Selected Rows( 0 ),

                List;

                Selected columns only( 0 )

);

 

Do you have other ideas, or should I do something completely different?

 

Cheers,

Christian

 

---------------------------------

Check out my JMP YouTube channel here for tips & tricks:

https://www.youtube.com/@statslikejazz
2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Making Subsets Smarter - Help Needed

I have created "add-in" (it has many other shortcuts that's why it is an add-in) which basically just sets shortcut to run simple script like

Current Data Table() << Subset(Selected Rows(1), Selected Columns Only(0));

jthi_0-1712306468631.png

You could also do this by creating a toolbar and adding shortcut to it.

-Jarmo

View solution in original post

txnelson
Super User

Re: Making Subsets Smarter - Help Needed

Your specified code only needs to be modified slightly to get what you want.

 

 

Dt = current data set();

Needs to be

 

Dt = current data table();

and the Subset Platform already can find all selected rows, and use that for the selection

 

Dt << Subset(
	Selected Rows( 1 ), 
	Selected columns( 0 )
);

Put it all together it looks like

Names Default To Here( 1 );
Dt = current data table();

Dt << Subset(
	Selected Rows( 1 ), 
	Selected columns( 0 )
);

As Jarmo suggests, you could turn this into a toolbar short cut.

Jim

View solution in original post

8 REPLIES 8
jthi
Super User

Re: Making Subsets Smarter - Help Needed

I have created "add-in" (it has many other shortcuts that's why it is an add-in) which basically just sets shortcut to run simple script like

Current Data Table() << Subset(Selected Rows(1), Selected Columns Only(0));

jthi_0-1712306468631.png

You could also do this by creating a toolbar and adding shortcut to it.

-Jarmo
Stats_Like_Jazz
Level III

Re: Making Subsets Smarter - Help Needed

Thanks for the answer Jarmo! I am creating an add-in with similar scripts that I find myself repeating! 

 

dot to comma is one of them XD

 

Names Default To Here( 1 );

dt = Current Data Table();

nr = nrows(dt);
col_names = dt << Get Selected Columns (String);// get column names (String);
for (i = 1, i <= nitems(col_names), i++,
    one_col = column(dt, col_names[i]);
    for (k = 1, k <= nr, k++,
        one_col[k] = substitute(one_col[k], ".", ",");    // Replace decimal with comma
        //one_col[k] = substitute(one_col[k], ",", ".");    // Replace comma with decimal
    );
    one_col << Data Type(Numeric);
    one_col << Set Modeling Type ("Continuous");
);

I got this from another community script.

---------------------------------

Check out my JMP YouTube channel here for tips & tricks:

https://www.youtube.com/@statslikejazz
txnelson
Super User

Re: Making Subsets Smarter - Help Needed

Your specified code only needs to be modified slightly to get what you want.

 

 

Dt = current data set();

Needs to be

 

Dt = current data table();

and the Subset Platform already can find all selected rows, and use that for the selection

 

Dt << Subset(
	Selected Rows( 1 ), 
	Selected columns( 0 )
);

Put it all together it looks like

Names Default To Here( 1 );
Dt = current data table();

Dt << Subset(
	Selected Rows( 1 ), 
	Selected columns( 0 )
);

As Jarmo suggests, you could turn this into a toolbar short cut.

Jim
Stats_Like_Jazz
Level III

Re: Making Subsets Smarter - Help Needed

Thanks Jim, that was a very helpful answer. 

 

Enjoy your weekend!

---------------------------------

Check out my JMP YouTube channel here for tips & tricks:

https://www.youtube.com/@statslikejazz
Stats_Like_Jazz
Level III

Re: Making Subsets Smarter - Help Needed

The given solution is already being used! thanks @txnelson and @jthi 

---------------------------------

Check out my JMP YouTube channel here for tips & tricks:

https://www.youtube.com/@statslikejazz
hogi
Level XIII

Re: Making Subsets Smarter - Help Needed

Before creating an Add-In on your own, you might have a look at QuickSelect Toolbar 

 

The option which you describe is this one:

hogi_1-1712420087565.png

 

There are many more Shortcut included -  like Tagging (~ Name Selection in Column on Steroids)

... and there is also a Shortcut for Invert selection :)

hogi
Level XIII

Re: Making Subsets Smarter - Help Needed

Actually, I started the Toolbar with a version like this one, returning a subset with just the selected rows and columns.

 

The current version includes now all columns - and is a linked subset. My work in Jmp would be much less efficient without it ...


application 1) select some points in a graph -> generate the subset

application 2) select some rows -> open the linked subset -> use the subset as a remote control to enter new values:

(view in My Videos)

 

If you prefer the other version, you could go to the AddIn folder and change the jsl code.
... or use a code similar to this one:

 

setting = Is Control Key(); // doesn't work with toolbars :(
dtSubset = Current Data Table() << Subset(
	Linked( Not( setting ) ),
	Suppress formula evaluation( 0 ),
	Selected Rows( 1 ),
	Selected columns only( setting )
);


Is there a trick how to get the CTRL status after triggering the script by a click on a toolbar icon?
Checking-for-modifier-keys-ctrl-alt-shift-in-script

GregF_JMP
Staff

Re: Making Subsets Smarter - Help Needed

Have you thought about row states: Hide & Exclude effectively create a subset for analysis without spawning new (or many) data tables?  This is a no scripting option that will also limit file sprawl.

This would be your alternative method/ except

no need to step 1 "save as", and

instead of step 5/delete  it would be right click hide and exclude (also in columns menu).

 

Since you mentioned doing this frequently- a few pointers for managing hidden/excluded row states:

  • If the selection can be done with column menu/ data filter for "show" and "include" then red triangle "save script to data table" and pick a descriptive name for the subset.  Clear row states when done, and re-run the script when this subset is needed again.

 

Or- make Row State Columns for each subset...

The Row State type data column can save all row state information including hidden/excluded, but also selected and row marker/color 

Example Below - sample file Big Class with two Row state columns added.

GregF_JMP_0-1712584240606.png

Subset #1: 13 year olds

  • Select 13 year olds, right click select matching, right click invert selection
  • Right Click Hide/Exclude the non 13's- the Subset of 13 year olds is now ready for analysis.

To preserve and return to this grouping

  • Make a new column of Data Type Row State (named RS_13)
  • Just for grins set 13 year old row markers to purple squares
  • Left Click on the star of RS_13 in columns pane- copy from row states (this sends the current row states to RS_13 column)
  • Protip- Column info- engage "Lock" because it is easy to inadvertently over-write

 

Also did this for a second subset sex=F, Notice how the row 3 selection is part of the saved row state.

  •  To deploy, from Row state red star, left click "Copy to Row States". (as illustrated)

 

 

Recommended Articles