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

- JMP User Community
- :
- Discussions
- :
- For Loop for Moving Data to New Columns

- 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

Created:
Nov 9, 2018 9:53 AM
| Last Modified: Nov 9, 2018 10:27 AM
(4389 views)

Is there an easier way, possibly with a For loop, to get data from multiple "cells" and move it to a new column? Otherwise, I was going to write the script similar to below:

```
dt<<New Column( "Demand Parameter", Character, "Nominal");
dt<<New Column( "Demand Parameter Value", Character, "Nominal");
Column(dt, "Demand Parameter")[9] = Column(dt, "Column 2")[7];
Column(dt, "Demand Parameter Value")[9] = Column(dt, "Column 2")[8];
Column(dt, "Demand Parameter")[10] = Column(dt, "Column 3")[7];
Column(dt, "Demand Parameter Value")[10] = Column(dt, "Column 3")[8];
//.... continue incrementing until finishing with the following
Column(dt, "Demand Parameter")[47] = Column(dt, "Column 40")[7];
Column(dt, "Demand Parameter Value")[47] = Column(dt, "Column 40")[8];
```

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

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

Thanks for replying to my question. Originally "Column 2" wasn't the second column... and "Column 40" wasn't the 40th but I rearranged my srcpit so that it is. I couldn't get your script to work but I did decide to use transpose. The following works as I intended. Thanks for the idea!

dt = Current Data Table();

collist = dt << get column names;

dt << Select Rows( {7,8} );

dt<<Transpose(

columns( eval(collist) ),

Source Label Column( "Label" ),

Transpose selected rows only( 1 ),

Output Table( "Transpose Demands" ));

dt2 = Data Table("Transpose Demands");

dt2 << Add Rows(7,0);

dt << Update( With( dt2 ));

Close(Data Table( "Transpose Demands" ), No Save);

dt << Delete Columns( "Label" );

3 REPLIES 3

Highlighted
##

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

Re: For Loop for Moving Data to New Columns

Approximately this:

**dt[ 9::47, { "Demand Parameter", "Demand Parameter Value" } ] = dt[ 7::8, 2::40 ] ` ;**

if "Column 2" is the second column... and "Column 40" is the 40th. Note the final, tiny, ` at the end that means Transpose. You could also list all the column names instead of 2::40. The transpose is needed to make the Left Hand Side and the Right Hand Side be the same shape, 39 rows and 2 columns.

See Data Table Subscripting blog post.

Craige

Highlighted

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

Thanks for replying to my question. Originally "Column 2" wasn't the second column... and "Column 40" wasn't the 40th but I rearranged my srcpit so that it is. I couldn't get your script to work but I did decide to use transpose. The following works as I intended. Thanks for the idea!

dt = Current Data Table();

collist = dt << get column names;

dt << Select Rows( {7,8} );

dt<<Transpose(

columns( eval(collist) ),

Source Label Column( "Label" ),

Transpose selected rows only( 1 ),

Output Table( "Transpose Demands" ));

dt2 = Data Table("Transpose Demands");

dt2 << Add Rows(7,0);

dt << Update( With( dt2 ));

Close(Data Table( "Transpose Demands" ), No Save);

dt << Delete Columns( "Label" );

Highlighted
##

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

Re: For Loop for Moving Data to New Columns

Glad you got a solution that works!

Craige

Article Labels

There are no labels assigned to this post.