Reordering an ordered list
Use the 'orrible old trick made famous(?) by old BASIC coders - set your orders to be 100, 200, 300, 400 etc. and then you can pick an order 'inbetween' when you need to. This could get messy - and if you're anticipating a lot of reordering then I'd recommend that you have a scheduled task to 'reorder' the order values every now and then for the entire table.
Reorder an element in an ordered list with a single update
A value m = (upper+lower)/2 is always in the middle of two values.
For further reading on numbering I refer to a lecture:
http://www.cs.uni-paderborn.de/fachgebiete/ag-boettcher/lehre/ss2012/dbis-2/download.html
Reordering data and making a re-ordered list in r
This is as easy as using unique
. I coerce to character
so as not to get confused between levels and actual values.
unique(as.character(dfordered$spp))
To get here from the original data, use table
table(df$spp)
## A B C
## 2 4 3
You can sort this
sppCount <- table(df$spp)
names(sort(sppCount, decreasing = TRUE))
# [1] "B" "C" "A"
python reordering of list elements with conversion to set
Thats because sets are based on the Hash Table data structure, where records are stored in buckets using hash keys, and the order of items (when printed or converted to list) depends on the hashes, but internally the order doest matter. so it doesnt really bother to change the order, it just adds the item and creates a hash index for it. when you print the set it is probably printed according to the lexographical order of hashes, or something like that.
As you can see from the following, the list when created from a set, takes the same order of hashes of these items.
>>> s=set([5,4,3,7,6,2,1,0])
>>> s
{0, 1, 2, 3, 4, 5, 6, 7}
>>> list(s)
[0, 1, 2, 3, 4, 5, 6, 7]
How can I reorder a list?
You can do it like this
mylist = ['a', 'b', 'c', 'd', 'e']
myorder = [3, 2, 0, 1, 4]
mylist = [mylist[i] for i in myorder]
print(mylist) # prints: ['d', 'c', 'a', 'b', 'e']
javascript - reorder a list without creating new list according to another list
- Use Array spread syntax or reduce your array of indexes into a DocumentFragment
- Finally, .append() the iterable to the same parent UL element.
const orderList = [3, 1, 2, 0];
const ul = document.querySelector('#list');
const li = ul.querySelectorAll('li');
ul.append(...orderList.map(i => li[i]));
<ul id="list">
<li>0</li>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
Reorder R list by unconventionally ordered vector?
It might help to take a look at ?"["
. Specifically, the difference between [[
and [
confused me for a while. Here, the key thing to note is that you can use [
to subset to multiple elements, while [[
can only be used for one element.
So as @lmo points out, what you want to do here is MyList[pattern]
. In case you didn't realize, this can work because names(MyList)
matches up with the elements in pattern
-- you can index/ subset not only by numerical index (e.g., 1:3
), but also by name (e.g., c("A","B","C")
).
TLDR:
NewList <- MyList[pattern]
Related Topics
Differencebetween Prepared Statements and SQL or Pl/Pgsql Functions, in Terms of Their Purpose
SQL Server Race Condition Question
Bigquery: How to Group and Count Rows Within Rolling Timestamp Window
Swap Values for Two Rows in the Same Table in SQL Server
SQL Server Insert into with Where Clause
To Get Column Names from Table Having a Particular Value
Ms SQL Server: Check to See If a User Can Execute a Stored Procedure
Can You Have a Foreign Key Onto a View of a Linked Server Table in SQLserver 2K5
Rename Single Column in Select * in SQL, Select All But a Column
How to Open Bcp Host Data-File
How to Call a Stored Procedure from Another Stored Procedure
SQL Scheduling - Select All Rooms Available for Given Date Range
Deleting a Row with a Self-Referencing Foreign Key
SQL Query to Count() Multiple Tables
Paging with Oracle and SQL Server and Generic Paging Method