BookmarkSubscribeRSS Feed

how to select rows with a specific number that user input

Winnie12

Occasional Contributor

Joined:

Jun 5, 2018

Hello everyone,

 

I am working on a project that helps users to pick modules based on their input. For example, if user input 5, the script would give user 5 modules that been selected. Could anyone one help me with the "select" part?

Bellow is my script, it gives users all of the possible results. But how can I only give user sepecific number of modules?

 

dt << Select Where( Column( "Shippable to Reliability?" )[Row()] == 1 );
dt << Subset( Selected Rows( 1 ), Output Table( "Best Modules" ) );

 

Thanks a lot,

Winnie

2 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

This should work

Names Default To Here( 1 );
dt << Select Where( Column( "Shippable to Reliability?" )[Row()] == 1 );
dtsub = dt << Subset( Selected Rows( 1 ), Output Table( "Best Modules" ) );

dtsub << New Column( "random", formula( Random Uniform() ) );

dtsub = dtsub << sort( by( :random ), order( ascending ), replace table( 1 ) );

dtsub << select where( Row() > 5 );
dtsub << delete rows;
dtsub << delete columns("random");
Jim
gzmorgan0

Community Trekker

Joined:

Jul 25, 2016

Just for fun, an alternate method.  

Names Default To Here( 1 );
dt   = open("$sample_data/big class.jmp");
idx  = Random Shuffle( dt <<  Get Rows Where( Column( "sex" )[]== "F" ) );
//get the matching rows but mix up the order;
show(idx); //for demonstration

//use only 5 of them
dtsub =  << Subset( rows(idx[1::5]), Output Table( "Best Modules" ) );