What is the Alphabetical Inequality Test?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Mathematica can sort "b","d","a","c"
into "a","b","c","d"
with a simple application of Sort
. What ordering function/command is being used?
It isn't <
: "a" < "b"
doesn't return True
or False
, just a < b
.
I'm trying to sort a large data set that contains both strings and numeric values. An example:
data = 9, 8, "b", 4, 2, "d", 0, 3, "a", 4, 9, "c"
.
I can sort by the second element of each set:
Sort[data, #2[[2]] > #1[[2]] &]
returns
4, 2, "d", 0, 3, "a", 9, 8, "b", 4, 9, "c"
.
But Sort
ing by the third element doesn't work:
Sort[data, #2[[3]] > #1[[3]] &]
returns data
unchanged:
9, 8, "b", 4, 2, "d", 0, 3, "a", 4, 9, "c"
.
It feels like a hack, but I can sort using Ordering
and OrderedQ
:
data[[Ordering[data[[All, 3]]]]]
returns
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
, as does
Sort[data, OrderedQ[#1[[3]], #2[[3]]] &]
.
Neither feels natural. Is there a lexicographical/alphabetical "inequality" command, or is it just OrderedQ
?
sorting
add a comment |Â
up vote
1
down vote
favorite
Mathematica can sort "b","d","a","c"
into "a","b","c","d"
with a simple application of Sort
. What ordering function/command is being used?
It isn't <
: "a" < "b"
doesn't return True
or False
, just a < b
.
I'm trying to sort a large data set that contains both strings and numeric values. An example:
data = 9, 8, "b", 4, 2, "d", 0, 3, "a", 4, 9, "c"
.
I can sort by the second element of each set:
Sort[data, #2[[2]] > #1[[2]] &]
returns
4, 2, "d", 0, 3, "a", 9, 8, "b", 4, 9, "c"
.
But Sort
ing by the third element doesn't work:
Sort[data, #2[[3]] > #1[[3]] &]
returns data
unchanged:
9, 8, "b", 4, 2, "d", 0, 3, "a", 4, 9, "c"
.
It feels like a hack, but I can sort using Ordering
and OrderedQ
:
data[[Ordering[data[[All, 3]]]]]
returns
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
, as does
Sort[data, OrderedQ[#1[[3]], #2[[3]]] &]
.
Neither feels natural. Is there a lexicographical/alphabetical "inequality" command, or is it just OrderedQ
?
sorting
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Mathematica can sort "b","d","a","c"
into "a","b","c","d"
with a simple application of Sort
. What ordering function/command is being used?
It isn't <
: "a" < "b"
doesn't return True
or False
, just a < b
.
I'm trying to sort a large data set that contains both strings and numeric values. An example:
data = 9, 8, "b", 4, 2, "d", 0, 3, "a", 4, 9, "c"
.
I can sort by the second element of each set:
Sort[data, #2[[2]] > #1[[2]] &]
returns
4, 2, "d", 0, 3, "a", 9, 8, "b", 4, 9, "c"
.
But Sort
ing by the third element doesn't work:
Sort[data, #2[[3]] > #1[[3]] &]
returns data
unchanged:
9, 8, "b", 4, 2, "d", 0, 3, "a", 4, 9, "c"
.
It feels like a hack, but I can sort using Ordering
and OrderedQ
:
data[[Ordering[data[[All, 3]]]]]
returns
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
, as does
Sort[data, OrderedQ[#1[[3]], #2[[3]]] &]
.
Neither feels natural. Is there a lexicographical/alphabetical "inequality" command, or is it just OrderedQ
?
sorting
Mathematica can sort "b","d","a","c"
into "a","b","c","d"
with a simple application of Sort
. What ordering function/command is being used?
It isn't <
: "a" < "b"
doesn't return True
or False
, just a < b
.
I'm trying to sort a large data set that contains both strings and numeric values. An example:
data = 9, 8, "b", 4, 2, "d", 0, 3, "a", 4, 9, "c"
.
I can sort by the second element of each set:
Sort[data, #2[[2]] > #1[[2]] &]
returns
4, 2, "d", 0, 3, "a", 9, 8, "b", 4, 9, "c"
.
But Sort
ing by the third element doesn't work:
Sort[data, #2[[3]] > #1[[3]] &]
returns data
unchanged:
9, 8, "b", 4, 2, "d", 0, 3, "a", 4, 9, "c"
.
It feels like a hack, but I can sort using Ordering
and OrderedQ
:
data[[Ordering[data[[All, 3]]]]]
returns
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
, as does
Sort[data, OrderedQ[#1[[3]], #2[[3]]] &]
.
Neither feels natural. Is there a lexicographical/alphabetical "inequality" command, or is it just OrderedQ
?
sorting
sorting
asked 4 hours ago
GregH
565516
565516
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
You can use AlphabeticOrder
:
data = 9, 8, "b", 4, 2, "d", 0, 3, "a", 4, 9, "c";
Sort[
data,
AlphabeticOrder[ #1[[3]], #2[[3]] ]&
]
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
That's it. I didn't seem to be using the right search terms online to find that command.
â GregH
3 hours ago
add a comment |Â
up vote
2
down vote
AlphabeticOrder
does not exist in version 10.1 which I use, but I don't believe it is necessary here. I argue that Order
and OrderedQ
are the more canonical (and certainly general) functions.
Additionally, where possible you should make use of SortBy
(e.g. SortBy[data, #[[3]] &]
) or Ordering
(as you already did) rather than Sort
, as these are more efficient methods.
An alternative to OrderedQ
if you have need of Sort
itself:
Sort[data, 0 < Order[#[[3]], #2[[3]]] &]
Sort[data, 0 > Order[#[[3]], #2[[3]]] &]
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
4, 2, "d", 4, 9, "c", 9, 8, "b", 0, 3, "a"
This is actually more concise than AlphabeticOrder
.
2
In law they say "lex specialis derogat legi generali": Sometimes the more special function has its merits and is maybe is less abstract?AlphabeticOrder
on the other hand is more general thanOrder
because English is not the only language out there... ;-)
â gwr
59 mins ago
@gwr I didn't notice that AlphabeticOrder handled different languages; that's nice! I have already voted for your answer. And thanks for the Latin lesson.
â Mr.Wizardâ¦
50 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
You can use AlphabeticOrder
:
data = 9, 8, "b", 4, 2, "d", 0, 3, "a", 4, 9, "c";
Sort[
data,
AlphabeticOrder[ #1[[3]], #2[[3]] ]&
]
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
That's it. I didn't seem to be using the right search terms online to find that command.
â GregH
3 hours ago
add a comment |Â
up vote
4
down vote
accepted
You can use AlphabeticOrder
:
data = 9, 8, "b", 4, 2, "d", 0, 3, "a", 4, 9, "c";
Sort[
data,
AlphabeticOrder[ #1[[3]], #2[[3]] ]&
]
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
That's it. I didn't seem to be using the right search terms online to find that command.
â GregH
3 hours ago
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
You can use AlphabeticOrder
:
data = 9, 8, "b", 4, 2, "d", 0, 3, "a", 4, 9, "c";
Sort[
data,
AlphabeticOrder[ #1[[3]], #2[[3]] ]&
]
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
You can use AlphabeticOrder
:
data = 9, 8, "b", 4, 2, "d", 0, 3, "a", 4, 9, "c";
Sort[
data,
AlphabeticOrder[ #1[[3]], #2[[3]] ]&
]
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
answered 3 hours ago
gwr
6,97622457
6,97622457
That's it. I didn't seem to be using the right search terms online to find that command.
â GregH
3 hours ago
add a comment |Â
That's it. I didn't seem to be using the right search terms online to find that command.
â GregH
3 hours ago
That's it. I didn't seem to be using the right search terms online to find that command.
â GregH
3 hours ago
That's it. I didn't seem to be using the right search terms online to find that command.
â GregH
3 hours ago
add a comment |Â
up vote
2
down vote
AlphabeticOrder
does not exist in version 10.1 which I use, but I don't believe it is necessary here. I argue that Order
and OrderedQ
are the more canonical (and certainly general) functions.
Additionally, where possible you should make use of SortBy
(e.g. SortBy[data, #[[3]] &]
) or Ordering
(as you already did) rather than Sort
, as these are more efficient methods.
An alternative to OrderedQ
if you have need of Sort
itself:
Sort[data, 0 < Order[#[[3]], #2[[3]]] &]
Sort[data, 0 > Order[#[[3]], #2[[3]]] &]
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
4, 2, "d", 4, 9, "c", 9, 8, "b", 0, 3, "a"
This is actually more concise than AlphabeticOrder
.
2
In law they say "lex specialis derogat legi generali": Sometimes the more special function has its merits and is maybe is less abstract?AlphabeticOrder
on the other hand is more general thanOrder
because English is not the only language out there... ;-)
â gwr
59 mins ago
@gwr I didn't notice that AlphabeticOrder handled different languages; that's nice! I have already voted for your answer. And thanks for the Latin lesson.
â Mr.Wizardâ¦
50 mins ago
add a comment |Â
up vote
2
down vote
AlphabeticOrder
does not exist in version 10.1 which I use, but I don't believe it is necessary here. I argue that Order
and OrderedQ
are the more canonical (and certainly general) functions.
Additionally, where possible you should make use of SortBy
(e.g. SortBy[data, #[[3]] &]
) or Ordering
(as you already did) rather than Sort
, as these are more efficient methods.
An alternative to OrderedQ
if you have need of Sort
itself:
Sort[data, 0 < Order[#[[3]], #2[[3]]] &]
Sort[data, 0 > Order[#[[3]], #2[[3]]] &]
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
4, 2, "d", 4, 9, "c", 9, 8, "b", 0, 3, "a"
This is actually more concise than AlphabeticOrder
.
2
In law they say "lex specialis derogat legi generali": Sometimes the more special function has its merits and is maybe is less abstract?AlphabeticOrder
on the other hand is more general thanOrder
because English is not the only language out there... ;-)
â gwr
59 mins ago
@gwr I didn't notice that AlphabeticOrder handled different languages; that's nice! I have already voted for your answer. And thanks for the Latin lesson.
â Mr.Wizardâ¦
50 mins ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
AlphabeticOrder
does not exist in version 10.1 which I use, but I don't believe it is necessary here. I argue that Order
and OrderedQ
are the more canonical (and certainly general) functions.
Additionally, where possible you should make use of SortBy
(e.g. SortBy[data, #[[3]] &]
) or Ordering
(as you already did) rather than Sort
, as these are more efficient methods.
An alternative to OrderedQ
if you have need of Sort
itself:
Sort[data, 0 < Order[#[[3]], #2[[3]]] &]
Sort[data, 0 > Order[#[[3]], #2[[3]]] &]
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
4, 2, "d", 4, 9, "c", 9, 8, "b", 0, 3, "a"
This is actually more concise than AlphabeticOrder
.
AlphabeticOrder
does not exist in version 10.1 which I use, but I don't believe it is necessary here. I argue that Order
and OrderedQ
are the more canonical (and certainly general) functions.
Additionally, where possible you should make use of SortBy
(e.g. SortBy[data, #[[3]] &]
) or Ordering
(as you already did) rather than Sort
, as these are more efficient methods.
An alternative to OrderedQ
if you have need of Sort
itself:
Sort[data, 0 < Order[#[[3]], #2[[3]]] &]
Sort[data, 0 > Order[#[[3]], #2[[3]]] &]
0, 3, "a", 9, 8, "b", 4, 9, "c", 4, 2, "d"
4, 2, "d", 4, 9, "c", 9, 8, "b", 0, 3, "a"
This is actually more concise than AlphabeticOrder
.
answered 1 hour ago
Mr.Wizardâ¦
228k294671023
228k294671023
2
In law they say "lex specialis derogat legi generali": Sometimes the more special function has its merits and is maybe is less abstract?AlphabeticOrder
on the other hand is more general thanOrder
because English is not the only language out there... ;-)
â gwr
59 mins ago
@gwr I didn't notice that AlphabeticOrder handled different languages; that's nice! I have already voted for your answer. And thanks for the Latin lesson.
â Mr.Wizardâ¦
50 mins ago
add a comment |Â
2
In law they say "lex specialis derogat legi generali": Sometimes the more special function has its merits and is maybe is less abstract?AlphabeticOrder
on the other hand is more general thanOrder
because English is not the only language out there... ;-)
â gwr
59 mins ago
@gwr I didn't notice that AlphabeticOrder handled different languages; that's nice! I have already voted for your answer. And thanks for the Latin lesson.
â Mr.Wizardâ¦
50 mins ago
2
2
In law they say "lex specialis derogat legi generali": Sometimes the more special function has its merits and is maybe is less abstract?
AlphabeticOrder
on the other hand is more general than Order
because English is not the only language out there... ;-)â gwr
59 mins ago
In law they say "lex specialis derogat legi generali": Sometimes the more special function has its merits and is maybe is less abstract?
AlphabeticOrder
on the other hand is more general than Order
because English is not the only language out there... ;-)â gwr
59 mins ago
@gwr I didn't notice that AlphabeticOrder handled different languages; that's nice! I have already voted for your answer. And thanks for the Latin lesson.
â Mr.Wizardâ¦
50 mins ago
@gwr I didn't notice that AlphabeticOrder handled different languages; that's nice! I have already voted for your answer. And thanks for the Latin lesson.
â Mr.Wizardâ¦
50 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184685%2fwhat-is-the-alphabetical-inequality-test%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password