Skip to main content
deleted 27 characters in body
Source Link
István Zachar
  • 47.2k
  • 20
  • 145
  • 293

The proper way to exploitUsing Odering (assuming that ref and set are of same length):

set[[Ordering@Ordering@ref]]

or a more complicated, less efficient way is:

pos = Range@Length@set;
set[[pos /. Thread[Ordering@ref -> pos]]]
{"E", "A", "D", "C", "B"}

MoreAn even more complicated way to do the same:

ref = {"e", "a", "d", "c", "b"};
set = {"A", "B", "C", "D", "E"};

order = Position[Sort@ref, #, 1][[1, 1]] & /@ ref
{5, 1, 4, 3, 2}
set[[order]]
{"E", "A", "D", "C", "B"}

The proper way to exploit Odering (assuming that ref and set are of same length):

set[[Ordering@Ordering@ref]]

or a more complicated, less efficient way is:

pos = Range@Length@set;
set[[pos /. Thread[Ordering@ref -> pos]]]
{"E", "A", "D", "C", "B"}

More complicated way to do the same:

ref = {"e", "a", "d", "c", "b"};
set = {"A", "B", "C", "D", "E"};

order = Position[Sort@ref, #, 1][[1, 1]] & /@ ref
{5, 1, 4, 3, 2}
set[[order]]
{"E", "A", "D", "C", "B"}

Using Odering (assuming that ref and set are of same length):

set[[Ordering@Ordering@ref]]

or a more complicated, less efficient way is:

pos = Range@Length@set;
set[[pos /. Thread[Ordering@ref -> pos]]]
{"E", "A", "D", "C", "B"}

An even more complicated way:

ref = {"e", "a", "d", "c", "b"};
set = {"A", "B", "C", "D", "E"};

order = Position[Sort@ref, #, 1][[1, 1]] & /@ ref
{5, 1, 4, 3, 2}
set[[order]]
{"E", "A", "D", "C", "B"}
deleted 277 characters in body
Source Link
István Zachar
  • 47.2k
  • 20
  • 145
  • 293

First you haveThe proper way to find the ordering of elements in the reference listexploit Odering (assuming that ref and set are of same length):

set[[Ordering@Ordering@ref]]

or a more complicated, less efficient way is:

pos = Range@Length@set;
set[[pos /. Thread[Ordering@ref -> pos]]]
{"E", "A", "D", "C", "B"}

More complicated way to do the same:

ref = {"e", "a", "d", "c", "b"};
set = {"A", "B", "C", "D", "E"};

order = Position[Sort@ref, #, 1][[1, 1]] & /@ ref
{5, 1, 4, 3, 2}
set[[order]]
{"E", "A", "D", "C", "B"}

Note, that using Ordering gives a different result, as it returns the ordering that sorts elements in ref:

Ordering@ref
set[[Ordering@ref]]
{2, 5, 4, 3, 1}

{"B", "E", "D", "C", "A"}

The proper way to exploit Odering (assuming that ref and set are of same length):

set[[Ordering@Ordering@ref]]

or a more complicated, less efficient way is:

pos = Range@Length@set;
set[[pos /. Thread[Ordering@ref -> pos]]]
{"E", "A", "D", "C", "B"}

First you have to find the ordering of elements in the reference list ref:

ref = {"e", "a", "d", "c", "b"};
set = {"A", "B", "C", "D", "E"};

order = Position[Sort@ref, #, 1][[1, 1]] & /@ ref
{5, 1, 4, 3, 2}
set[[order]]
{"E", "A", "D", "C", "B"}

Note, that using Ordering gives a different result, as it returns the ordering that sorts elements in ref:

Ordering@ref
set[[Ordering@ref]]
{2, 5, 4, 3, 1}

{"B", "E", "D", "C", "A"}

The proper way to exploit Odering (assuming that ref and set are of same length):

set[[Ordering@Ordering@ref]]

or a more complicated, less efficient way is:

pos = Range@Length@set;
set[[pos /. Thread[Ordering@ref -> pos]]]
{"E", "A", "D", "C", "B"}

The proper way to exploit Odering (assuming that ref and set are of same length):

set[[Ordering@Ordering@ref]]

or a more complicated, less efficient way is:

pos = Range@Length@set;
set[[pos /. Thread[Ordering@ref -> pos]]]
{"E", "A", "D", "C", "B"}

More complicated way to do the same:

ref = {"e", "a", "d", "c", "b"};
set = {"A", "B", "C", "D", "E"};

order = Position[Sort@ref, #, 1][[1, 1]] & /@ ref
{5, 1, 4, 3, 2}
set[[order]]
{"E", "A", "D", "C", "B"}
added 85 characters in body
Source Link
István Zachar
  • 47.2k
  • 20
  • 145
  • 293

First you have to find the ordering of elements in the reference list ref:

ref = {"e", "a", "d", "c", "b"};
set = {"A", "B", "C", "D", "E"};

order = Position[Sort@ref, #, 1][[1, 1]] & /@ ref
{5, 1, 4, 3, 2}
set[[order]]
{"E", "A", "D", "C", "B"}

Note, that using Ordering gives a different result, as it returns the ordering that sorts elements in ref:

Ordering@ref
set[[Ordering@ref]]
{2, 5, 4, 3, 1}

{"B", "E", "D", "C", "A"}

The proper way to exploit Odering (assuming that ref and set are of same length):

set[[Ordering@Ordering@ref]]

or a more complicated, less efficient way is:

pos = Range@Length@set;
set[[pos /. Thread[Ordering@ref -> pos]]]
{"E", "A", "D", "C", "B"}

First you have to find the ordering of elements in the reference list ref:

ref = {"e", "a", "d", "c", "b"};
set = {"A", "B", "C", "D", "E"};

order = Position[Sort@ref, #, 1][[1, 1]] & /@ ref
{5, 1, 4, 3, 2}
set[[order]]
{"E", "A", "D", "C", "B"}

Note, that using Ordering gives a different result, as it returns the ordering that sorts elements in ref:

Ordering@ref
set[[Ordering@ref]]
{2, 5, 4, 3, 1}

{"B", "E", "D", "C", "A"}

The proper way to exploit Odering (assuming that ref and set are of same length):

pos = Range@Length@set;
set[[pos /. Thread[Ordering@ref -> pos]]]
{"E", "A", "D", "C", "B"}

First you have to find the ordering of elements in the reference list ref:

ref = {"e", "a", "d", "c", "b"};
set = {"A", "B", "C", "D", "E"};

order = Position[Sort@ref, #, 1][[1, 1]] & /@ ref
{5, 1, 4, 3, 2}
set[[order]]
{"E", "A", "D", "C", "B"}

Note, that using Ordering gives a different result, as it returns the ordering that sorts elements in ref:

Ordering@ref
set[[Ordering@ref]]
{2, 5, 4, 3, 1}

{"B", "E", "D", "C", "A"}

The proper way to exploit Odering (assuming that ref and set are of same length):

set[[Ordering@Ordering@ref]]

or a more complicated, less efficient way is:

pos = Range@Length@set;
set[[pos /. Thread[Ordering@ref -> pos]]]
{"E", "A", "D", "C", "B"}
added 204 characters in body
Source Link
István Zachar
  • 47.2k
  • 20
  • 145
  • 293
Loading
added 29 characters in body
Source Link
István Zachar
  • 47.2k
  • 20
  • 145
  • 293
Loading
Source Link
István Zachar
  • 47.2k
  • 20
  • 145
  • 293
Loading