cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
ram
ram
Level IV

How to get entire row values using JSL?

HI All,

how we can get intire row values using jsl for a given row?

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: How to get entire row values using JSL?

In JMP 13 you can use data table subscripting

dt = Open( "$sample_data/big class.jmp" );
row5 = dt[5, 0];
Show( row5 );

row5 = {"LILLIE", 12, "F", 52, 64};

Craige

View solution in original post

5 REPLIES 5
ian_jmp
Staff

Re: How to get entire row values using JSL?

If you only have numeric columns, you could exploit 'GetAsMatrix'. If you have character and numeric columns, you could use 'GetAllColumnsAsMatrix', but then you still have to handle the coded character values. So, in the latter case, it might be simpler to just define a function:

NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

getRow =
Function({tbl, rn}, {DefaultLocal},
	rowContents = {};
	for(c=1, c<=NCols(dt), c++,
		InsertInto(rowContents, Column(tbl, c)[rn]);
	);
	rowContents;
);

Print(getRow(dt, 5));

 

Craige_Hales
Super User

Re: How to get entire row values using JSL?

In JMP 13 you can use data table subscripting

dt = Open( "$sample_data/big class.jmp" );
row5 = dt[5, 0];
Show( row5 );

row5 = {"LILLIE", 12, "F", 52, 64};

Craige
ian_jmp
Staff

Re: How to get entire row values using JSL?

Nice!

Note how data table subscripting gives either a list or matrix, as needed:

NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << colorByColumn(:sex);
r4Vals = dt[4,0];
Print(r4Vals);
dt << deleteColumns({:name, :sex});
r4Vals = dt[4,0];
Print(r4Vals);
rsc = dt << NewColumn("Row States", Row State);
rsc << copyFromRowStates;
r4Vals = dt[4,0];
Print(r4Vals);
dt << NewColumn("Expression", Expression);
r4Vals = dt[4,0];
Print(r4Vals);
aronwilson
Level II

Re: How to get entire row values using JSL?

Subscripting data tables is very handy but is it possible to use the "by" function in this (for example by( :age )) to pull all the names of people who have the same age into the column?

 

Here is an example:

I'd like to take all the names where the age is the same and concatenate them in a column.

One of the common next steps is then summarizing other columns by those concatenated names.

 

2018-05-02_3-59-31.png2018-05-02_4-01-21.png

I've dug through and tried multiple approaches and I think I'm just missing something simple, but what I'm hoping is that there is a very straightforward way to do this using either subscription or something like
dt:name << get values(by(age)) and then either put that in a column or use it in a script.

 

I tried this as a formula column: 

dt[Index( :first_row, :last_row ), {:name}]

 

And each subexpression provided the correct result to match your example 

 

// fetch a list if character columns are involved. 
// notice the matrix is reversing the order
dt[ 4::2, "name"]; // {"JACLYN", "JANE", "LOUISE"}

but I'm not able to get the actual list of names {"JACLYN", "JANE", "LOUISE"} to return in the column.

  

Thank you for any help,

 

Aron

aronwilson
Level II

Re: How to get entire row values using JSL?

Apparently, all I needed to do was post and I instantly found an answer.

 

fr = Col Minimum( Row(), :age );
lr = Col Maximum( Row(), :age );
dt:name[Index( fr, lr )];
//returns {"KATIE", "LOUISE", "JANE", "JACLYN", "LILLIE", "TIM", "JAMES", "ROBERT"}

This is exactly what I was looking for.

Using the col min and max with row is pretty simple, so that works.

However, I am curious if it's possible to use a by(age) argument in the subscript directly, I've used it in Make Validation Column and it makes it so much easier to do.

 

Thank you,

 

Aron