Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Sorting a list of pairs on the second elements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51412] Re: [mg51372] Re: Sorting a list of pairs on the second elements
  • From: János <janos.lobb at yale.edu>
  • Date: Sat, 16 Oct 2004 04:20:51 -0400 (EDT)
  • References: <cklmi7$f1o$1@smc.vnet.net> <200410150647.CAA05265@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Oct 15, 2004, at 2:47 AM, Peltio wrote:

> "János" wrote
>
>>    Map[Reverse,Sort[Map[Reverse,collectedDnaBin]]]
>
>>    Sort[collectedDnaBin,#1[[2]] < #2[[2]] &]
>> but that does not want to do the trick for me.
>
> I wonder why. It should work, albeit inefficently. Mmmmm, have you  
> tried
> with parenthesis wrapped around the pure function?
>     Sort[collectedDnaBin,(#1[[2]] < #2[[2]])&]
> Have you tried it in a fresh kernel?

Yes, and yes.  It does not work.
In[31]:=
Sort[sss, (Last[#1] < Last[#2] )&]

Out[31]=
{{gggcggcgacctcgcgggttttcgctatttatgaaaattttccggtttaaggcgtttccgttcttcttcg 
  \
tcataacttaatgtttttatttaaaatacc,1},{\
tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaaagtatttatcg,13}, 
{\
tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaa,12},{\
tatttttgtaattcaatactgcttcttctt,11},{aaattttccggtttaaggcgtttccgttcttcttcg 
tca,\
122},{aaattttccggtttaaggcgtttccgttctt,121},{ttcttgcctttgcgg,1211},{\
actgcttcttcttgcctttgcggaatttg,1221},{\
gctatttatgaaaattttccggtttaaggcgtttccgttcttcttcgtcataa,133},{\
gctatttatgaaaattttccggtttaaggcg,132},{gctatttat,131},{gcggaatttggcctttta 
aa,\
1321},{aaattttcc,13211},{aatactgcttcttcttgcctttgcggaatttggccttttaaaagt,1 
331},{\
tgaaaattttccggttt,13311}}

Maybe because they are Strings ?  I am just guessing...
>
>> In general, if I have a list whose elements are m-member lists, like
>> {{a1,...,am},...,{z1,...,zm}}, then my question is what is the
>> best/fastest way to sort it on the k-th elements of the members where
>> 1<=k<=m and ak,...,zk are arbitrary objects - in my case Strings - and
>> use as little memory for it as possible.
>
> Dunno for the general case, but this -very inelegant - approach to sort
> according to the last element seems to be pretty fast (lots of  
> procedures
> but applied to the data as a whole, without timeconsuming mapping on  
> every
> single element)
>
>     Transpose@Reverse@Transpose@Sort@Transpose@Reverse@Transpose[
> collectedDnaBin ]

This one works fine.

>
> ( The first and last three procs just implement a swap function
>     swap[list_]:=Transpose@Reverse@Transpose[list]
> )
>
> The group's gurus will certainly find a proc at least ten times faster  
> than
> this, I'm sure.

I don't know.  The suggestions I got via the list and private are all  
excellent, but the data I had to sort got so big that I even did not  
get to that point to able to sort because the Kernel just quitted on me  
half way.  Now I am on a different "war-path" to get the results I need  
:)  /My secret prayers go out for a real 64-bit, or MORE, Mathematica  
on OSX..../

Thanks a lot,

János
>
> cheers,
> Peltio
> Invalid address in reply-to. Crafty demunging required to mail me.

I tried to employ Mathematica in "Crafty demunging" but I failed, so I  
send it "as is".  Now I embrace for an "Addressee not found..."  
thunder... :)
>
>
>

-------------------------------------------------------------------
János Löbb
Yale University School of Medicine
Department of Pathology
Phone: 203-737-5204
Fax:      203-785-7303
E-mail: janos.lobb at yale.edu


  • Prev by Date: Re: Question about derivatives
  • Next by Date: Re: Solving an equation
  • Previous by thread: Re: Sorting a list of pairs on the second elements
  • Next by thread: Re: Re: Re: Sorting a list of pairs on the second elements