Group Abstract Group Abstract

Message Boards Message Boards

0
|
9K Views
|
3 Replies
|
1 Total Like
View groups...
Share
Share this post:

Sort a table with respect to other?

Posted 8 years ago
Attachments:
POSTED BY: S G
3 Replies

I would do the following:

B[[Permute[Ordering[B[[All,{2,3}]]], Ordering[A[[All,{2,3}]]]]]]
POSTED BY: Carl Woll

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

Step 1. for every element in A, there is a corresponding element in B. The first step is to write a function that takes in an element from A and gives the corresponding element from B.

  • To do this, first write a function that checks whether an element from A and an element from B match.
  • Then use the Select function to make the function in Step 1.

Step 2. Go thru every element in A and replace it with the corresponding element in B.

  • The cleanest way to do this is with Map. You may prefer using a For loop or using Replace depending on your coding style.

I'm not sure what your programming experience is. Can you write a function that takes two elements (one from A and one from B) and checks whether they match each other?

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard