Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- JMP User Community
- :
- Discussions
- :
- Create a column formula using a column name from a list

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 17, 2020 10:13 AM
(552 views)

Hello,

I have a simple script where I want to create a new column in which a formula calculate the absolute value of another column.

the column is referenced in a list.

I tried a few different ways, but I can't figure out how to evaluate the referenced column so I end up with an empty formula column. Any suggestion would be greatly appreciated.

Best

Sebastien

```
dt=New Table( "test",
Add Rows( 4 ),
New Column( "symbol",
Character,
"Nominal",
Set Values( {"a", "b", "c", "d"} ),
Set Display Width( 55 )
),
New Column( "fold change",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [-3, -0.4, 0.4, 3] ),
Set Display Width( 68 )
)
);
l={"fold change"};
try(New Column( "absolute fold change",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Abs( l[1] )
)));
try(New Column( "absolute fold change 2",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( eval(column(l[1]) )
)));
```

2 ACCEPTED SOLUTIONS

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

```
dt=New Table( "test",
Add Rows( 4 ),
New Column( "symbol",
Character,
"Nominal",
Set Values( {"a", "b", "c", "d"} ),
Set Display Width( 55 )
),
New Column( "fold change",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [-3, -0.4, 0.4, 3] ),
Set Display Width( 68 )
)
);
l = {"fold change"};
try(New Column( "absolute fold change",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Abs( column( l[1] )[] )
)));
```

Since your list contains only strings, you need to tell JMP that the string is a column name by using the Column( "" )[ ] function.

The blank square brackets are necessary as well as without them, the formula will reference the *entire column *instead of only the appropriate row.

Hope this helped,

Lain

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

No problem. I had this exact same issue yesterday and it took me a while to figure it out.

I actually just learned of another solution to this, too.

The 'As Column()' function will return the value of the current row in the column specified as an argument.

So that formula could equally have been formatted like this:

Formula(

Abs( As Column( l[1] ) );

);

Pretty neat!

I actually just learned of another solution to this, too.

The 'As Column()' function will return the value of the current row in the column specified as an argument.

So that formula could equally have been formatted like this:

Formula(

Abs( As Column( l[1] ) );

);

Pretty neat!

3 REPLIES 3

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

```
dt=New Table( "test",
Add Rows( 4 ),
New Column( "symbol",
Character,
"Nominal",
Set Values( {"a", "b", "c", "d"} ),
Set Display Width( 55 )
),
New Column( "fold change",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [-3, -0.4, 0.4, 3] ),
Set Display Width( 68 )
)
);
l = {"fold change"};
try(New Column( "absolute fold change",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Abs( column( l[1] )[] )
)));
```

Since your list contains only strings, you need to tell JMP that the string is a column name by using the Column( "" )[ ] function.

The blank square brackets are necessary as well as without them, the formula will reference the *entire column *instead of only the appropriate row.

Hope this helped,

Lain

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Create a column formula using a column name from a list

Thanks a lot, I had tried the option you proposed with one big difference: No empty brackets.

Best,

Sebastien

Best,

Sebastien

Highlighted
No problem. I had this exact same issue yesterday and it took me a while to figure it out.

I actually just learned of another solution to this, too.

The 'As Column()' function will return the value of the current row in the column specified as an argument.

So that formula could equally have been formatted like this:

Formula(

Abs( As Column( l[1] ) );

);

Pretty neat!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

I actually just learned of another solution to this, too.

The 'As Column()' function will return the value of the current row in the column specified as an argument.

So that formula could equally have been formatted like this:

Formula(

Abs( As Column( l[1] ) );

);

Pretty neat!