1
$\begingroup$

I want to sort this table by column "d" such that Mathematica should also take the exponential values into account. Can somebody help me here?

Table

$\endgroup$
5
  • $\begingroup$ Welcome to Mathematica StackExchange! Please edit your question and include all relevant information, including your table and any Mathematica code you are using. $\endgroup$
    – Domen
    Mar 28, 2023 at 14:03
  • $\begingroup$ The input is: Partition[Flatten[fitteddata], Length[fitteddata[[1]]]] // TableForm and I want to keep the first row. $\endgroup$
    – Miss
    Mar 28, 2023 at 14:14
  • $\begingroup$ No, it's not possible as it's an output of many input files. I just want to know if there is a trick to sorting such Flatten table. $\endgroup$
    – Miss
    Mar 28, 2023 at 14:23
  • $\begingroup$ @Miss, evaluate Partition[Flatten[fitteddata], Length[fitteddata[[1]]]] (without TableForm!) , and paste the ouput in your question. $\endgroup$
    – Domen
    Mar 28, 2023 at 14:32
  • $\begingroup$ Welcome to the Mathematica Stack Exchange. You can learn to ask better questions by visiting the site's Help page. Thanks. $\endgroup$
    – Syed
    Mar 28, 2023 at 16:16

1 Answer 1

2
$\begingroup$

it's not possible as it's an output of many input files

This makes it little harder, but here is an example.

The idea is to use SortBy[data, #[[5]] &] this sorts the whole data using 5th column as key . Make sure not to use TableForm when sorting as it is a wrapper. Do the SortBy on the row data before adding the tittle row and before adding TableForm to it.

title = {"phiA(deg)", "z0", "w", "l", "d", "dnm", "ξ", "ζ"}
data = {{33, 50, 0.00008, 0.01, 1.0*10^(-8), 4.8*10^(-9), 1, 1},
  {24.3, 50, 0.00008, 0.01, 1.1*10^(-8), 4.8*10^(-9), 1, 1},
  {38, 50, 0.00008, 0.01, 1.2*10^(-8), 4.8*10^(-9), 1, 1},
  {30, 50, 0.00008, 0.01, 1.3*10^(-8), 4.8*10^(-9), 1, 1},
  {22, 50, 0.00008, 0.01, 0.9*10^(-8), 4.8*10^(-9), 1, 1},
  {35, 50, 0.00008, 0.01, 0.8*10^(-8), 4.8*10^(-9), 1, 1},
  {30, 50, 0.00008, 0.01, 1.5*10^(-8), 4.8*10^(-9), 1, 1}
  }

Mathematica graphics

Now sort the data (without the title row) then add the title row next

dataSorted = SortBy[data, #[[5]] &] (*sort on 5th column*)
({title}~Join~dataSorted) // TableForm

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.