cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

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