Message Boards Message Boards

0
|
7083 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Sort a table with respect to other?

Posted 7 years ago

Hi, I have two 36 X 3 tables. First columns in both of them are independent terms/numbers, while second and third columns have same indices (numbers) from 1 - 6, but in different orders. I want to arrange the rows of table B in the same order as in A, with respect to second and third elements of them. For example if

A = {{X, 2, 1}, {Y, 2, 3}, {Z, 2, 4}...}

and

B = {{x, 2, 3}, {y, 2, 4}, {z, 2, 1}....}

I want B to be rearranged to

B_new = {{z, 2, 1}, {x, 2, 3}, {y, 2, 4}....}

Will be thankful for any suggestion. Attached is the *.nb file having these tables.

Attachments:
POSTED BY: S G
3 Replies
POSTED BY: Carl Woll
POSTED BY: Sean Clarke

You can try this way:

Bnew = With[{restA = Map[Rest, A]},
  Sort[B, OrderedQ[{Position[restA, Rest[#1]],
      Position[restA, Rest[#2]]}] &]]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract