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
matt7109
Level III

JSL: Iterate through columns

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

Re: JSL: Iterate through columns

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

View solution in original post

1 REPLY 1
txnelson
Super User

Re: JSL: Iterate through columns

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