I had looked at previous answers for this but was unable to find a solution. I have the following code:
dnames1={"A1","A2","A3","A4","A5","A6"}
dnumber={20,20,11,21,19,20}
newdnumber=TakeSmallest[dnumber,6]
AssociationThread[dnames,dnumber]
The positions of the strings given in "dnames1" correspond to the values in the same position given by list "dnumber" (this can be seen through the AssociationThread
). I then rearranged the list "dnumber" to go from the smallest number to the largest, giving a new list designated "newdnumber." I'm trying to then produce a new corresponding list called "newdnames1" which reflects the new ordering given by "newdnumber." This would give an output of:
newdnames1={"A3","A5","A1","A2","A6","A4"}
I've tried the following to solve this question:
assoc=AssociationThread[dnumber,dnames1]
newdnumber/.assoc
but the main issue is that the AssociationThread
does not associate the correct list of strings if there are repeating values given in dnumber (I.e. The number 20 appears 3 times but the association only ever assigns "A6"`a value of 20 and it never assigns strings "A1" or "A2". Any help producing newdnames1 would be greatly appreciated.
dnames1[[Ordering[dnumber]]]
to getnewdnames1
directly? $\endgroup$Keys@Sort@AssociationThread[dnames1, dnumber]
$\endgroup$