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
- :
- joining matrices by matching columns

Topic Options

- 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
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 26, 2015 5:58 PM
(1923 views)

Does anyone have a sleek script for joining matrices in the way joining tables does (by matching columns)?

Thanking you all in advance,

Ron

1 ACCEPTED SOLUTION

Accepted Solutions

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

Oct 27, 2015 4:17 AM
(3450 views)

Solution

Only slightly tongue in cheek do I suggest the following. It might seem perverse, but, on the other hand, getting JMP to do the work for you is always good. In this case it would take some effort to re-invent the flexibility of 'Join()' in the world of matrices.

NamesDefaultToHere**(****1****)**;

// Joins two matrices 'm1' and 'm2' using the key columns 'c1' and 'c2' (all columns are retained)

joinMatrices =

Function**({**m1, c1, m2, c2**}**, **{**Default Local**}**,

dt1 = AsTable**(**m1, << **Invisible****)**;

dt2 = AsTable**(**m2, << **Invisible****)**;

// Edit the 'Join()' expression to taste . . .

dt3 = dt1 << **Join****(**

With**(** dt2 **)**,

By Matching Columns**(** "Col"||Char**(**c1**)** = "Col"||Char**(**c2**)** **)**,

Drop multiples**(** **0**, **0** **)**,

Include Nonmatches**(** **0**, **0** **)**,

Preserve main table order**(** **1** **)**,

Invisible

**)**;

m3 = dt3 << **getAsMatrix**;

Close**(**dt1, NoSave**)**;

Close**(**dt2, NoSave**)**;

Close**(**dt3, NoSave**)**;

m3;

**)**;

// Make a couple of matrices

n = **10**; // Number of rows

m1 = **(****1**::n**)**`||J**(**n, n, **10****)**;

m2 = RandomShuffle**(**m1**[****0**,**1****])**||Identity**(**n**)**;

// Test the function

joinMatrices**(**m1, **1**, m2, **1****)**;

7 REPLIES

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

Oct 27, 2015 4:17 AM
(3451 views)

Only slightly tongue in cheek do I suggest the following. It might seem perverse, but, on the other hand, getting JMP to do the work for you is always good. In this case it would take some effort to re-invent the flexibility of 'Join()' in the world of matrices.

NamesDefaultToHere**(****1****)**;

// Joins two matrices 'm1' and 'm2' using the key columns 'c1' and 'c2' (all columns are retained)

joinMatrices =

Function**({**m1, c1, m2, c2**}**, **{**Default Local**}**,

dt1 = AsTable**(**m1, << **Invisible****)**;

dt2 = AsTable**(**m2, << **Invisible****)**;

// Edit the 'Join()' expression to taste . . .

dt3 = dt1 << **Join****(**

With**(** dt2 **)**,

By Matching Columns**(** "Col"||Char**(**c1**)** = "Col"||Char**(**c2**)** **)**,

Drop multiples**(** **0**, **0** **)**,

Include Nonmatches**(** **0**, **0** **)**,

Preserve main table order**(** **1** **)**,

Invisible

**)**;

m3 = dt3 << **getAsMatrix**;

Close**(**dt1, NoSave**)**;

Close**(**dt2, NoSave**)**;

Close**(**dt3, NoSave**)**;

m3;

**)**;

// Make a couple of matrices

n = **10**; // Number of rows

m1 = **(****1**::n**)**`||J**(**n, n, **10****)**;

m2 = RandomShuffle**(**m1**[****0**,**1****])**||Identity**(**n**)**;

// Test the function

joinMatrices**(**m1, **1**, m2, **1****)**;

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

Oct 27, 2015 6:26 AM
(1725 views)

thanks Ian@JMP for the script and the tip.

I agree that the power of JMP is outstanding and much easier to work with than scripting crude commands using matrices. in my case it also saves a huge amount of time since i can quickly make "hands on" checks that it is doing what i intended by using the interactive interface at any step.

the thing is the script i wrote in which all the process uses data tables - summarizing, joining, comparing, deleting rows and extracting values. i was hoping to make it faster by converting it to matrices but i notice this will not be the case.

Ron

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

Oct 27, 2015 6:39 AM
(1725 views)

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

Oct 27, 2015 10:42 AM
(1725 views)

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

Oct 27, 2015 11:53 AM
(1725 views)

thanks msharp, this is useful to know.

what about table summary? deleting multiple rows? deleting multiple columns?

Ron

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

Oct 27, 2015 1:16 PM
(1725 views)

Yes, all those functions should be multithreaded.

Multithreading largely isn't supported in JSL (this is for the most part a good thing). However, if that were true for JMP itself the program would be super slow and unusable to an end user. Most send commands '<<' tend to be multithreaded b/c they are native to JMP, although not all.

Just test out a function if you have a question on it. For example, open up your Task Manager and run something like this:

dt = new table**(**"test"**)**;

dt << **New Column(**"test", Numeric, Continuous, Values**(****1**::**100000000))**;

dt << **Delete Rows(1**::**100000000)**;

clost**(**dt, nosave**)**;

When I run this you can see all four of my processors spiking.

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

Oct 27, 2015 2:15 PM
(1725 views)