- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
JSL: Creating formula using a variable column name
Hi,
I want to do an actually simple thing (at least I thought so), namely to create a new column using JSL with a formula that contains a variable column name. I already tried several combinations of the commands "column, as column, name, as name, eval, parse .." and I searched the forum, but everything I tried results in an error that the formula could not be evaluated.
An example what I want to do:
"column 1" is a column in my data table.
a = "column 1";
new column("test", formula(a*2));
The column "test" should contain the formula that multiplies "column 1" with 2.
Thanks for any help,
Dahla
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL: Creating formula using a variable column name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL: Creating formula using a variable column name
I tried but cant get it work on a variant.
There are two column where the user chooses in a custom dialog box, and i assign them the names of lx,ly.
I need a new column with formula
Radius = SQRT((X^2)+(Y^2))
However, when i run it, althought the new column is created, JMP prompt me
"N Items() argument must be a list", and no formula created.
Appreciate if a kind soul can advice on which part is faulty. Thanks.
customDlg << CloseWindow;
lp = colListP << GetItems;
lx = colListX << GetItems;
ly = colListY << GetItems;
// Are the user selections viable?
if (NItems(lp) < 1,
Dialog("ERROR: Select one or more Parameter Columns", Button("OK")); Throw());
if (NItems(lx) != 1,
Dialog("ERROR: You need to select an X Column", Button("OK")); Throw(),
xVar = lx(1)
);
if (NItems(ly) != 1,
Dialog("ERROR: You need to select a Y Column", Button("OK")); Throw(),
yVar = ly(1)
);
// *********************************************************************************
// Build New Column with new formula
// *********************************************************************************
dt = Current Data Table();
a = Column(dt,xvar);
b = Column(dt,yvar);
colx = ;
coly = ;
nlist = N Items(a);
For( i = 1, i <= nlist, i++,
newColExpr = Expr(
dt << New Column( "Radius", Numeric,
Formula( Root((Power(Expr(a(i)),2)+Power(Expr(b(i)),2)),2 ) ) );
Eval( Eval Expr( newColExpr ) );
);
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL: Creating formula using a variable column name
Here's an example using the Column Dialog which gives the user the choice to select exactly 2 columns from which the Radius column will be created.
dt = Current Data Table();
cdlg = Column Dialog( clist = ColList( "Pick 2 Columns", Min Col( 2 ), Max Col( 2 ) ) );
cols = cdlg["clist"];
newColExpr = Expr( dt << New Column( "Radius", Numeric, Formula( Sqrt( Expr( cols[1] ) ^ 2 + Expr( cols[2] ) ^ 2 ) ) ) );
Eval( Eval Expr( newColExpr ) );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL: Creating formula using a variable column name
=)
- « Previous
-
- 1
- 2
- Next »