Canonical ordering of days of weekSorting a list with secondary criterionSort strings by natural orderingWhy can't I remove Orderless from Plus?Sort matrix by columns and rows without changing themNon-canonical re-ordering of nested listsHow to sort colors properly?Sorting the words of a phrase by defined variables/associationsBin arbitrary data using canonical orderingOrdering a list of integers
What is the need of methods like GET and POST in the HTTP protocol?
How to deal with my team leader who keeps calling me about project updates even though I am on leave for personal reasons?
How can I repair this gas leak on my new range? Teflon tape isn't working
Canonical ordering of days of week
How to ask a man to not take up more than one seat on public transport while avoiding conflict?
What was the deeper meaning of Hermione wanting the cloak?
What benefits does the Power Word Kill spell have?
1, 2, 4, 8, 16, ... 33?
How use custom order in folder on Windows 7 and 10
What can a pilot do if an air traffic controller is incapacitated?
Is it possible to encode a message in such a way that can only be read by someone or something capable of seeing into the very near future?
Hilbert's hotel, why can't I repeat it infinitely many times?
As an employer, can I compel my employees to vote?
What is this utensil for?
Resolving moral conflict
delete object network in cisco ASA with packet tracert
Cut a cake into 3 equal portions with only a knife
What is the meaning of word 'crack' in chapter 33 of A Game of Thrones?
Do you need to hold concentration on a spell when you cast it with a spell scroll?
Are actors contractually obligated to certain things like going nude/ Sensual Scenes/ Gory Scenes?
What are these pixel-level discolored specks? How can I fix it?
Where does an unaligned creature's soul go after death?
What are these ingforms of learning?
Is It Possible to Have Different Sea Levels, Eventually Causing New Landforms to Appear?
Canonical ordering of days of week
Sorting a list with secondary criterionSort strings by natural orderingWhy can't I remove Orderless from Plus?Sort matrix by columns and rows without changing themNon-canonical re-ordering of nested listsHow to sort colors properly?Sorting the words of a phrase by defined variables/associationsBin arbitrary data using canonical orderingOrdering a list of integers
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
The entities representing the days of the week sort alphabetically:
Sort[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
(* Friday, Monday, Saturday, Sunday, Thursday, Tuesday, Wednesday *)
(Note that these are not strings.)
Is there a better way to sort than using the following?
SortBy[PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday]]
sorting
$endgroup$
add a comment
|
$begingroup$
The entities representing the days of the week sort alphabetically:
Sort[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
(* Friday, Monday, Saturday, Sunday, Thursday, Tuesday, Wednesday *)
(Note that these are not strings.)
Is there a better way to sort than using the following?
SortBy[PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday]]
sorting
$endgroup$
$begingroup$
Wouldn't this be ill-defined because it is cyclic? I guess you could order them if you agree on which day is the first of the week… some say monday, others sunday…
$endgroup$
– SHuisman
10 hours ago
$begingroup$
"Canonically" (i.e. according to the Bible) the first day was Sunday.
$endgroup$
– mikado
1 hour ago
add a comment
|
$begingroup$
The entities representing the days of the week sort alphabetically:
Sort[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
(* Friday, Monday, Saturday, Sunday, Thursday, Tuesday, Wednesday *)
(Note that these are not strings.)
Is there a better way to sort than using the following?
SortBy[PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday]]
sorting
$endgroup$
The entities representing the days of the week sort alphabetically:
Sort[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
(* Friday, Monday, Saturday, Sunday, Thursday, Tuesday, Wednesday *)
(Note that these are not strings.)
Is there a better way to sort than using the following?
SortBy[PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday]]
sorting
sorting
asked 11 hours ago
Stephen PowellStephen Powell
6673 silver badges12 bronze badges
6673 silver badges12 bronze badges
$begingroup$
Wouldn't this be ill-defined because it is cyclic? I guess you could order them if you agree on which day is the first of the week… some say monday, others sunday…
$endgroup$
– SHuisman
10 hours ago
$begingroup$
"Canonically" (i.e. according to the Bible) the first day was Sunday.
$endgroup$
– mikado
1 hour ago
add a comment
|
$begingroup$
Wouldn't this be ill-defined because it is cyclic? I guess you could order them if you agree on which day is the first of the week… some say monday, others sunday…
$endgroup$
– SHuisman
10 hours ago
$begingroup$
"Canonically" (i.e. according to the Bible) the first day was Sunday.
$endgroup$
– mikado
1 hour ago
$begingroup$
Wouldn't this be ill-defined because it is cyclic? I guess you could order them if you agree on which day is the first of the week… some say monday, others sunday…
$endgroup$
– SHuisman
10 hours ago
$begingroup$
Wouldn't this be ill-defined because it is cyclic? I guess you could order them if you agree on which day is the first of the week… some say monday, others sunday…
$endgroup$
– SHuisman
10 hours ago
$begingroup$
"Canonically" (i.e. according to the Bible) the first day was Sunday.
$endgroup$
– mikado
1 hour ago
$begingroup$
"Canonically" (i.e. according to the Bible) the first day was Sunday.
$endgroup$
– mikado
1 hour ago
add a comment
|
3 Answers
3
active
oldest
votes
$begingroup$
It is not much shorter than your PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday], but you can also use System`DateObjectDump`$dowAssociation:
System`DateObjectDump`$dowAssociation
<|Monday -> 1, Tuesday -> 2, Wednesday -> 3, Thursday -> 4,
Friday -> 5, Saturday -> 6, Sunday -> 7|>
sortByDoW = SortBy[System`DateObjectDump`$dowAssociation];
Examples:
sortByDoW @ Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
sortByDoW @ RandomSample[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
$endgroup$
add a comment
|
$begingroup$
As you've noticed, the weekday symbols are by default sorted by their symbol names. This is because Monday,... are not true date specifications, but only day types. So there is not really a canonical ordering. However, you could do the following:
SortBy[DayPlus[DayPlus[Today, 1, Sunday], 1, #] &]@
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
(* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday *)
This works by converting the day types into actual dates. This is done in three steps:
- Find the next Sunday after today (you could also hardcode the date of a sunday here, but this is more readable I think)
- Find the date of the first Monday/... after that point
- Sort these dates
$endgroup$
add a comment
|
$begingroup$
You could define your own special sorting function. Like so:
With[ordered = Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
With[indexed = PositionIndex[ordered],
sortByDay[data_] := SortBy[data, indexed[#] &]]]
Tests
sortByDay @ Tuesday, Monday, Friday, Saturday, Thursday, Sunday, Wednesday
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
sortByDay @ Wednesday, Saturday, Thursday, Sunday, Tuesday, Friday, Monday
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
$endgroup$
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f206489%2fcanonical-ordering-of-days-of-week%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
It is not much shorter than your PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday], but you can also use System`DateObjectDump`$dowAssociation:
System`DateObjectDump`$dowAssociation
<|Monday -> 1, Tuesday -> 2, Wednesday -> 3, Thursday -> 4,
Friday -> 5, Saturday -> 6, Sunday -> 7|>
sortByDoW = SortBy[System`DateObjectDump`$dowAssociation];
Examples:
sortByDoW @ Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
sortByDoW @ RandomSample[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
$endgroup$
add a comment
|
$begingroup$
It is not much shorter than your PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday], but you can also use System`DateObjectDump`$dowAssociation:
System`DateObjectDump`$dowAssociation
<|Monday -> 1, Tuesday -> 2, Wednesday -> 3, Thursday -> 4,
Friday -> 5, Saturday -> 6, Sunday -> 7|>
sortByDoW = SortBy[System`DateObjectDump`$dowAssociation];
Examples:
sortByDoW @ Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
sortByDoW @ RandomSample[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
$endgroup$
add a comment
|
$begingroup$
It is not much shorter than your PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday], but you can also use System`DateObjectDump`$dowAssociation:
System`DateObjectDump`$dowAssociation
<|Monday -> 1, Tuesday -> 2, Wednesday -> 3, Thursday -> 4,
Friday -> 5, Saturday -> 6, Sunday -> 7|>
sortByDoW = SortBy[System`DateObjectDump`$dowAssociation];
Examples:
sortByDoW @ Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
sortByDoW @ RandomSample[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
$endgroup$
It is not much shorter than your PositionIndex[Monday, Tuesday, Wednesday, Thursday, Friday], but you can also use System`DateObjectDump`$dowAssociation:
System`DateObjectDump`$dowAssociation
<|Monday -> 1, Tuesday -> 2, Wednesday -> 3, Thursday -> 4,
Friday -> 5, Saturday -> 6, Sunday -> 7|>
sortByDoW = SortBy[System`DateObjectDump`$dowAssociation];
Examples:
sortByDoW @ Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
sortByDoW @ RandomSample[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
answered 4 hours ago
kglrkglr
217k10 gold badges247 silver badges498 bronze badges
217k10 gold badges247 silver badges498 bronze badges
add a comment
|
add a comment
|
$begingroup$
As you've noticed, the weekday symbols are by default sorted by their symbol names. This is because Monday,... are not true date specifications, but only day types. So there is not really a canonical ordering. However, you could do the following:
SortBy[DayPlus[DayPlus[Today, 1, Sunday], 1, #] &]@
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
(* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday *)
This works by converting the day types into actual dates. This is done in three steps:
- Find the next Sunday after today (you could also hardcode the date of a sunday here, but this is more readable I think)
- Find the date of the first Monday/... after that point
- Sort these dates
$endgroup$
add a comment
|
$begingroup$
As you've noticed, the weekday symbols are by default sorted by their symbol names. This is because Monday,... are not true date specifications, but only day types. So there is not really a canonical ordering. However, you could do the following:
SortBy[DayPlus[DayPlus[Today, 1, Sunday], 1, #] &]@
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
(* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday *)
This works by converting the day types into actual dates. This is done in three steps:
- Find the next Sunday after today (you could also hardcode the date of a sunday here, but this is more readable I think)
- Find the date of the first Monday/... after that point
- Sort these dates
$endgroup$
add a comment
|
$begingroup$
As you've noticed, the weekday symbols are by default sorted by their symbol names. This is because Monday,... are not true date specifications, but only day types. So there is not really a canonical ordering. However, you could do the following:
SortBy[DayPlus[DayPlus[Today, 1, Sunday], 1, #] &]@
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
(* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday *)
This works by converting the day types into actual dates. This is done in three steps:
- Find the next Sunday after today (you could also hardcode the date of a sunday here, but this is more readable I think)
- Find the date of the first Monday/... after that point
- Sort these dates
$endgroup$
As you've noticed, the weekday symbols are by default sorted by their symbol names. This is because Monday,... are not true date specifications, but only day types. So there is not really a canonical ordering. However, you could do the following:
SortBy[DayPlus[DayPlus[Today, 1, Sunday], 1, #] &]@
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
(* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday *)
This works by converting the day types into actual dates. This is done in three steps:
- Find the next Sunday after today (you could also hardcode the date of a sunday here, but this is more readable I think)
- Find the date of the first Monday/... after that point
- Sort these dates
answered 11 hours ago
Lukas LangLukas Lang
9,7591 gold badge13 silver badges36 bronze badges
9,7591 gold badge13 silver badges36 bronze badges
add a comment
|
add a comment
|
$begingroup$
You could define your own special sorting function. Like so:
With[ordered = Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
With[indexed = PositionIndex[ordered],
sortByDay[data_] := SortBy[data, indexed[#] &]]]
Tests
sortByDay @ Tuesday, Monday, Friday, Saturday, Thursday, Sunday, Wednesday
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
sortByDay @ Wednesday, Saturday, Thursday, Sunday, Tuesday, Friday, Monday
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
$endgroup$
add a comment
|
$begingroup$
You could define your own special sorting function. Like so:
With[ordered = Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
With[indexed = PositionIndex[ordered],
sortByDay[data_] := SortBy[data, indexed[#] &]]]
Tests
sortByDay @ Tuesday, Monday, Friday, Saturday, Thursday, Sunday, Wednesday
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
sortByDay @ Wednesday, Saturday, Thursday, Sunday, Tuesday, Friday, Monday
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
$endgroup$
add a comment
|
$begingroup$
You could define your own special sorting function. Like so:
With[ordered = Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
With[indexed = PositionIndex[ordered],
sortByDay[data_] := SortBy[data, indexed[#] &]]]
Tests
sortByDay @ Tuesday, Monday, Friday, Saturday, Thursday, Sunday, Wednesday
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
sortByDay @ Wednesday, Saturday, Thursday, Sunday, Tuesday, Friday, Monday
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
$endgroup$
You could define your own special sorting function. Like so:
With[ordered = Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
With[indexed = PositionIndex[ordered],
sortByDay[data_] := SortBy[data, indexed[#] &]]]
Tests
sortByDay @ Tuesday, Monday, Friday, Saturday, Thursday, Sunday, Wednesday
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
sortByDay @ Wednesday, Saturday, Thursday, Sunday, Tuesday, Friday, Monday
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
answered 10 hours ago
m_goldbergm_goldberg
91.6k8 gold badges75 silver badges209 bronze badges
91.6k8 gold badges75 silver badges209 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f206489%2fcanonical-ordering-of-days-of-week%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Wouldn't this be ill-defined because it is cyclic? I guess you could order them if you agree on which day is the first of the week… some say monday, others sunday…
$endgroup$
– SHuisman
10 hours ago
$begingroup$
"Canonically" (i.e. according to the Bible) the first day was Sunday.
$endgroup$
– mikado
1 hour ago