Subscribe Bookmark RSS Feed

Max value of each row across multiple columns JMP10

ravi_sasjmp

New Contributor

Joined:

Nov 14, 2016

When I run below script in JMP 10, I get an error message that says - argument should be matrix{1} in access or evaluation of 'Loc Max' , Bad Argument ...

Looks like data table indexing is a feature in JMP13. What would be the work around in JMP10?

dt = New Table( "Untitled",
New Column( "a", Numeric, Set Values( [1, 33, 1] ) ),
New Column( "b", Numeric, Set Values( [2, 2, 2] ) ),
New Column( "c", Numeric, Set Values( [333, 1, 0] ) ),
New Column( "maxval", numeric ),
New Column( "maxcol", Numeric )
);

colnames = dt << getcolumnnames;

For Each Row(
r = Row();
// 1::3 means columns 1 through 3. {a,b,c} would also work.
location = Loc Max( dt[ r, 1 :: 3] ); // location of maximum value in array
maxval = dt[r, location];
maxcol = colnames[location] << getname;
);

 

Thanks!

1 REPLY
markbailey

Staff

Joined:

Jun 23, 2011

You can get the values as a matrix first and then grab each row from the matrix instead of the data table:

dt = New Table( "Untitled",
	New Column( "a", Numeric, Set Values( [1, 33, 1] ) ),
	New Column( "b", Numeric, Set Values( [2, 2, 2] ) ),
	New Column( "c", Numeric, Set Values( [333, 1, 0] ) ),
	New Column( "maxval", numeric ),
	New Column( "maxcol", Numeric )
);

colnames = dt << getcolumnnames;

values = dt << Get As Matrix;

For Each Row(
	r = Row();
	// 1::3 means columns 1 through 3. {a,b,c} would also work.
	location = Loc Max( values[r, 1 :: 3] ); // location of maximum value in array
	maxval = dt[r, location];
	maxcol = colnames[location] << getname;
);
Learn it once, use it forever!