cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
David_Hanslian
Level II

Loop to set a normalization formula for several columns

Hi community,

I'm trying to write a JSL script to set a normalization formula with dynamic column reference. 

 

What's wrong here?
"Mean(M4_pop)" & "Std Dev(M4_pop)" are fix columns that are to be used for the normalization. 

 

dt = Current Data Table();

numCols = dt << Get Column Names( Numeric, "String" );

For( i = 1, i <= N Items( numCols ), i++,

     colName = numCols[i];  

    normColName = colName || "_norm";

    dt << New Column(

        normColName,

        Numeric,

        Continuous,

        Formula( (colName- :"Mean(M4_pop)"n) / :"Std Dev(M4_pop)"n)

    );

    );

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Loop to set a normalization formula for several columns

Hi David,

 

there might be prettier solutions but this is one way to make it work:

 

dt = Current Data Table();

numCols = dt << Get Column Names( Numeric, "String" );

For( i = 1, i <= N Items( numCols ), i++,

    colName = numCols[i];
     
    mean = "Mean(M4_pop)";
    
    std =  "Std Dev(M4_pop)";

    normColName = colName || "_norm";

    dt << New Column(

        normColName,

        Numeric,

        Continuous,

        Formula( (as column(colName)- as column (mean)) / as column(Std))

    );

    );
    

Cheers,

Jonas

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Loop to set a normalization formula for several columns

You will have to evaluate colName to the formula
Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute 

-Jarmo

Re: Loop to set a normalization formula for several columns

Hi David,

 

there might be prettier solutions but this is one way to make it work:

 

dt = Current Data Table();

numCols = dt << Get Column Names( Numeric, "String" );

For( i = 1, i <= N Items( numCols ), i++,

    colName = numCols[i];
     
    mean = "Mean(M4_pop)";
    
    std =  "Std Dev(M4_pop)";

    normColName = colName || "_norm";

    dt << New Column(

        normColName,

        Numeric,

        Continuous,

        Formula( (as column(colName)- as column (mean)) / as column(Std))

    );

    );
    

Cheers,

Jonas

David_Hanslian
Level II

Re: Loop to set a normalization formula for several columns

Hi Jonas,

 

thanks for your response. Small changes that led to sucess :) 

Recommended Articles