Turn on suggestions

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

Showing results for

- JMP User Community
- :
- Discussions
- :
- copy column from one table to another (bring the formula and the heading

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

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

copy column from one table to another (bring the formula and the heading

Aug 16, 2019 12:13 PM
(269 views)

Hi. I have two tables. one with the heading and formula I need.

And at other tables is the one with the formulas. How can copy the column from one table (bring the formula and the heading) to another. Thanks

3 REPLIES 3

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

Re: copy column from one table to another (bring the formula and the heading

Here is an example of one way to do this

```
Names Default To Here( 1 );
dt = New Table( "Source",
add rows( 20 ),
New Column( "A", formula( Random Integer( 1, 10 ) ) ),
New Column( "B", formula( Random Integer( 20, 30 ) ) )
);
dt << run formulas;
dt2 = New Table( "Copy", add rows( 10 ) );
// Create the columns and set the names and formula
For( i = 1, i <= N Cols( dt ), i++,
dt2 << New Column( Column( dt, i ) << get name );
theFormula = Char( Column( dt, i ) << get formula );
Eval(
Parse(
"Column( dt2, Column( dt," || Char( i ) || ")<< get name ) <<
set formula( " || theFormula || ");"
)
);
);
```

Jim

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

Re: copy column from one table to another (bring the formula and the heading

Hi thanks! Sorry but I cant understand the script. Would you explain for me in another way?

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

Re: copy column from one table to another (bring the formula and the heading

If your original post was not talking using a script to do the copying, then what you need to do, is to use

Tables==>Subset

Below is a more fully annotated version of the script.

```
// This script creates a couple of example data tables and then runs
// a little script that copies all of the columns from the originating
// data table to a new data table
// Setup the memory environment
Names Default To Here( 1 );
// Create an example data table that has some formula columns
// The variable "dt" is used as a pointer to this data table
dt = New Table( "Source",
add rows( 20 ),
New Column( "A", formula( Random Integer( 1, 10 ) ) ),
New Column( "B", formula( Random Integer( 20, 30 ) ) )
);
dt << run formulas;
// Create a new data table that will be used to create the new
// columns in
// Variable "dt2" is used to point to this data table
dt2 = New Table( "Copy", add rows( 10 ) );
// Create the columns and set the names and formula
// Loop across all columns in the Originating data table
// and retireve the name and formula and then create a new
// column in the new data table
For( i = 1, i <= N Cols( dt ), i++,
// Create the new column in the new data table, giving it
// the name from the current data table
dt2 << New Column( Column( dt, i ) << get name );
// Get the formula from the originating data table
theFormula = Char( Column( dt, i ) << get formula );
// Set the formula into the new data table
Eval(
Parse(
"Column( dt2, Column( dt," || Char( i ) || ")<< get name ) <<
set formula( " || theFormula || ");"
)
);
);
```

Jim