cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
jeric
Level I

Column formula referencing variable column names


Greetings,

For analyzing electrical data I want to create new columns with an absolute value formula referring to other columns whose names may be different in different data sets but start with "ID" or "IG".   When I apply below the formula for every new column is the absolute value using the last measurement column found, not the column corresponding to different measurement columns.  How should I express that each "ABS" formula applies to the measurement column?

cdt = Current Data Table();

ColNames = {};

ColNames=cdt<< Get Column Names(string);

for (i=1, i<= N items(ColNames), i++,

if (Substr(ColNames ,1,2) == "ID" |

     Substr(ColNames ,1,2)== "IG" ,

    (

      col = Column(i);

      New Column("ABS " || ColNames , (Formula(Abs(As Column (col)))), format("Scientific", 6, 1));

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Level X

Re: Column formula referencing variable column names

NamesDefaultToHere(1);

// Make a table . . .

dt = NewTable("ETEST",

  NewColumn("ID_1", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("ID_2", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("Not Required", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("IG_1", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("IG_2", Numeric, Continuous, Formula(RandomNormal())),

  AddRows(10)

);

// Add new formula columns as required . . .

cols = dt << GetColumnNames("String");

Wait(3);

For(c=1, c<=NItems(cols), c++,

  If(StartsWith(cols[c], "ID") | StartsWith(cols[c], "IG"),

  // Template expression for adding the new column by a formula

  CMD = Expr( dt << NewColumn("ABS("||cols[c]||")", Numeric, Continuous, Formula(Abs(colTBD))) );

  // Update the expression with values for this iteration . . .

  SubstituteInto(CMD, Expr(colTBD), AsName(cols[c]));

  // Add the required column

  CMD;

  );

);

View solution in original post

2 REPLIES 2
ian_jmp
Level X

Re: Column formula referencing variable column names

NamesDefaultToHere(1);

// Make a table . . .

dt = NewTable("ETEST",

  NewColumn("ID_1", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("ID_2", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("Not Required", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("IG_1", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("IG_2", Numeric, Continuous, Formula(RandomNormal())),

  AddRows(10)

);

// Add new formula columns as required . . .

cols = dt << GetColumnNames("String");

Wait(3);

For(c=1, c<=NItems(cols), c++,

  If(StartsWith(cols[c], "ID") | StartsWith(cols[c], "IG"),

  // Template expression for adding the new column by a formula

  CMD = Expr( dt << NewColumn("ABS("||cols[c]||")", Numeric, Continuous, Formula(Abs(colTBD))) );

  // Update the expression with values for this iteration . . .

  SubstituteInto(CMD, Expr(colTBD), AsName(cols[c]));

  // Add the required column

  CMD;

  );

);

jeric
Level I

Re: Column formula referencing variable column names

Works like a charm.  Thank you, sir!