- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
How to reorder columns in one table based on row entries in another table?
I have two tables - a subset of columns in table 1 have names which are also rows entries (in a column, say column 7) in table 2.
table 2 rows are sorted in a desired (ascending) order.
I would like to reorder only those columns in table 1 which have column names occurring in table 2 in the order they are sorted (in column 7) in table 2.
How to achieve this via JSL?
When it's too good to be true, it's neither
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to reorder columns in one table based on row entries in another table?
Here is an example of one way to handle the question
names default to here(1);
table1 =
// Open Data Table: semiconductor capability.jmp
// → Data Table( "semiconductor capability" )
Open( "$SAMPLE_DATA/Big Class.jmp" );
table2 = New Table("Table 2",
New Column("Sort Order", character,
Values({"height","weight","sex"})
)
);
For( i = N Rows( table2 ), i >= 1, i--,
Try(
table1 << go to( Column( table2, 1 )[i] );
table1 << Move Selected Columns( To first );
)
);
Jim
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to reorder columns in one table based on row entries in another table?
Few questions:
- Where should the columns be sorted?
- Should they be sorted in place?
- Should they be first columns in the table?
- Should they be last columns in the table?
- Should they start from the first column to be sorted in the table?
- Is the order in table 2 based on column 7 or some other columns?
- Are there example data tables (table1 and table 2) and then table 1 with desired results?
-Jarmo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to reorder columns in one table based on row entries in another table?
@jthi All valid questions. I will try to answer them below.
- Where should the columns be sorted? Do you mean re-order? Re-ordered columns should be in table 1 (not new table)?
- Should they be sorted in place? Table 1 has more columns than those which need reordering. See next.
- Should they be first columns in the table? Can do.
- Should they be last columns in the table? Can do. I can handle both option 2 and 3.
- Should they start from the first column to be sorted in the table? The order of (re-ordered) columns in table 1 should be in the order they appear as row entries in (col 7 of) table 2.
- Is the order in table 2 based on column 7 or some other columns? I smell confusion here. I will try again. Row entries in column 7 of table 2 is ordered in a desired order. Row entries in column 7 of table 2 are also column names in table 1. I want to re-order the these "common" columns in table 1 in the sequence they appear in table 2.
- Are there example data tables (table1 and table 2) and then table 1 with desired results? I cannot share actual data, but I will try to cook something up and share.
When it's too good to be true, it's neither
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to reorder columns in one table based on row entries in another table?
Created:
May 12, 2023 09:04 AM
| Last Modified: May 12, 2023 2:47 PM
(1565 views)
| Posted in reply to message from Neo 05-12-2023
@jthi Thanks
When it's too good to be true, it's neither
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to reorder columns in one table based on row entries in another table?
Here is an example of one way to handle the question
names default to here(1);
table1 =
// Open Data Table: semiconductor capability.jmp
// → Data Table( "semiconductor capability" )
Open( "$SAMPLE_DATA/Big Class.jmp" );
table2 = New Table("Table 2",
New Column("Sort Order", character,
Values({"height","weight","sex"})
)
);
For( i = N Rows( table2 ), i >= 1, i--,
Try(
table1 << go to( Column( table2, 1 )[i] );
table1 << Move Selected Columns( To first );
)
);
Jim