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

Sorting the Elements of a Non Rectangular List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51181] Sorting the Elements of a Non Rectangular List
  • From: Richard Palmer <mapsinc at bellatlantic.net>
  • Date: Thu, 7 Oct 2004 05:26:10 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Make two data structures h1 and h2.

\!\(\(h1 = 
      Sort[Table[key\_\(Random[Integer, {1, 30}]\), {i, 1, 8}]]
/. 
        key\_i_ -> {key\_i, info\_\(i, 1\), info\_\(i, 2\)};\)\)

\!\(\(h2 = 
      Sort[Table[{key\_\(Random[Integer, {1, 30}]\), 

Sort[Table[
                info\_\(Random[Integer, {3, 20}]\), {Random[

Integer, {0, 12}]}]]}, {9}]];\)\)

Define a function tensorize which adds keys that aren't on one set onto
another.

tensorize[x_, using_] := 
  Flatten[{x, 

Transpose[{Complement[First[Transpose[using]], First[Transpose[x]]]}]}, 

1]

How do I sort tensorize[h1,h2] into key order?

Sort[tensorize[h1,h2]] does not work and
Sort[tensorize[h1,h2],First[#1]<=Sort[#2]&] does not work?

Thanks in advance.


  • Prev by Date: Variance of sample and whole dataset
  • Next by Date: RenderMan RI bindings for Mathematica
  • Previous by thread: Re: Variance of sample and whole dataset
  • Next by thread: Re: Sorting the Elements of a Non Rectangular List