- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Add new column with formula to data table at certain position
Is it possible to add a new column to a data table (a) at a certain position (e.g. after a particular column) and (b) assign it a formula?
The New Column command can do (a) and the Add Multiple Columns command can do (b), but is there a way to get both done in one go?
Something like the command below (which does not give the desired result, however):
dt << New Column( "NewCol",
After(:Col3),
Numeric,
Continuous,
Format( "Best", 5 ),
Formula( :Col3 * 2 )
);
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Add new column with formula to data table at certain position
I think you need a couple of steps:
dt = Open("$SAMPLE_DATA/Big Class.jmp");
WAit(2);
dt << NewColumn("BMI", Numeric, Continuous, Formula(:weight/:height^2));
Wait(2);
dt << MoveSelectedColumns({:BMI}, After(:sex));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Add new column with formula to data table at certain position
I think you need a couple of steps:
dt = Open("$SAMPLE_DATA/Big Class.jmp");
WAit(2);
dt << NewColumn("BMI", Numeric, Continuous, Formula(:weight/:height^2));
Wait(2);
dt << MoveSelectedColumns({:BMI}, After(:sex));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Add new column with formula to data table at certain position
I think you have your a and b mixed up. Add Multiple Columns permits you to add the new columns at a specific point relative to other columns—Before First, After Last, or after a select column—and is otherwise quite limited with what you can preset for the new columns. New Column will permit you to set any number of column properties such as a formula, but lacks a parameter for placement. As Ian suggested, the way to achieve what you want is to define the new column using New Column then use Move Selected Columns to place the column in the data table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Add new column with formula to data table at certain position
True!