Subscribe Bookmark RSS Feed

JSL: Iterate through columns

matt7109

Contributor

Joined:

Jun 9, 2017

Hi, I have 2 questions (very new to this!)

 

First, I have multple columns of like data, and I need to apply the same formula to all of them. For example, if I had to find the mean of each column, can I automate that through some sort of iteration?

 

Second, how do I go about saving an operation as a list and not as a new column? For exmaple, if I had the following operation creating a new column in my chart

dt << New Column( "Example", Numeric, Formula(Col Mean( :Height, :Age ) ) );

(Basically finding the mean height for each age), could I simply store this operation as a list that can be used in another operation, rather than a column on my chart?

 

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

The script below handles your first issue

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

colnames = dt << get column names( numeric,string );
meanlist = {};
For( i = 1, i <= N Items( colnames ), i++,
	meanlist[i] = Col Mean( column(dt,colnames[i]) )
);

For the second issue, you could meet what you need by creating a character column and then create your 2 or more calculations, convert each of them into a character string, and then concatinate the values together, to place them into a List, convert the list to a string:  Char(MyList)......which would end up looking like "{45, 34}";

Or lastly, you could save the list as an expression.

 

But as far as JMP automatically handling the results in analyses, it currently does not have that capability

Jim
1 REPLY
txnelson

Super User

Joined:

Jun 22, 2012

Solution

The script below handles your first issue

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

colnames = dt << get column names( numeric,string );
meanlist = {};
For( i = 1, i <= N Items( colnames ), i++,
	meanlist[i] = Col Mean( column(dt,colnames[i]) )
);

For the second issue, you could meet what you need by creating a character column and then create your 2 or more calculations, convert each of them into a character string, and then concatinate the values together, to place them into a List, convert the list to a string:  Char(MyList)......which would end up looking like "{45, 34}";

Or lastly, you could save the list as an expression.

 

But as far as JMP automatically handling the results in analyses, it currently does not have that capability

Jim