cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Have your say in shaping JMP's future by participating in the new JMP Wish List Prioritization Survey
Choose Language Hide Translation Bar
lukasz
Level IV

How to select data in column based on the position of a value

Hello everybody,

iteratively for each item group I need to select data from column Param2 based on the row position of the "1" in the column Param (see picture below). How can I do that?

lukasz_0-1624963819101.png

Best regards

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to select data in column based on the position of a value

Here is little script that recreates your sample data table, and then does the selection

txnelson_0-1624967543173.png

Names Default To Here( 1 );
// recreate the example data table
dt = New Table( "Example",
	Add Rows( 14 ),
	New Column( "Item",
		Character,
		"Nominal",
		Set Values( {"A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "C", "C", "C", "C"} )
	),
	New Column( "Param",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [0.8, 1, 0.9, 1.1, 1.2, 0.9, 0.8, 1, 0.7, 0.8, 0.5, 1, 0.9, 1.1] ),
		Set Display Width( 46 )
	),
	New Column( "Param2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [2.1, 2, 2.3, 2.4, 2.5, 3.3, 3.2, 3.4, 3, 3.7, 2.5, 5.5, 5.4, 5.6] )
	)
);

// select the required rows
Summarize( dt, group = by( :Item ) );
dt << clear select;
For( i = 1, i <= N Items( group ), i++,
	theRow = (dt << get rows where( :Item == group[i] & :Param == 1 ))[1];
	dt << select where( :Item == group[i] & Row() >= theRow, current selection( "extend" ) );
);

 

Jim

View solution in original post

1 REPLY 1
txnelson
Super User

Re: How to select data in column based on the position of a value

Here is little script that recreates your sample data table, and then does the selection

txnelson_0-1624967543173.png

Names Default To Here( 1 );
// recreate the example data table
dt = New Table( "Example",
	Add Rows( 14 ),
	New Column( "Item",
		Character,
		"Nominal",
		Set Values( {"A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "C", "C", "C", "C"} )
	),
	New Column( "Param",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [0.8, 1, 0.9, 1.1, 1.2, 0.9, 0.8, 1, 0.7, 0.8, 0.5, 1, 0.9, 1.1] ),
		Set Display Width( 46 )
	),
	New Column( "Param2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [2.1, 2, 2.3, 2.4, 2.5, 3.3, 3.2, 3.4, 3, 3.7, 2.5, 5.5, 5.4, 5.6] )
	)
);

// select the required rows
Summarize( dt, group = by( :Item ) );
dt << clear select;
For( i = 1, i <= N Items( group ), i++,
	theRow = (dt << get rows where( :Item == group[i] & :Param == 1 ))[1];
	dt << select where( :Item == group[i] & Row() >= theRow, current selection( "extend" ) );
);

 

Jim