Trying to add last 4 columns together based on variable column names<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />Hi there, I have a DT that is imported into jmp and what I am trying to create a formula to add the last 4 columns together. This is fine if the names where static and the dt had the same amount of columns but unfortunalty thiis is not the case.
The DT could have 7 to 10 columns dependent on the raw data pull and the column names are also variable. My question would be, is it possible to just create a formula for these last 4 columns and add them together, even if i didnt know the column names.
I have got the following to add specific columns:
/*Set Variables to the column locations */
a = column name (14);
b = column name (15);
c = column name (16);
d = column name (17);
/* Create a new column and add the 4 column variables together */
NewColumn("ADD_LST_4",Numeric,Formula(a[]+b[]+c[]+d[]),EvalFormula);
Where i am falling down to to choose the last 4 columns and not the specific locations
any ideas?
Rgds
Lodey
Re: Trying to add last 4 columns together based on variable column namesTo get a column variable from column number you can use a = Column(1).
Here is one way to do it by script, although i think there may exist a more elegant way.
dt = Open( "$SAMPLE_DATA/Baltic.jmp" );
col = (dt << get column names())[N Col( dt ) - 3 :: N Col( dt )]; //list of last 4 columns
dt << New Column( "Sum", numeric );
For Each Row( :Sum[] = Sum( Column( col[1] )[], Column( col[2] )[], Column( col[3] )[], Column( col[4] )[] ) );