0

I have a spreadsheet with 100 columns and 5000 rows, which I imported into Mathematica as a list named data.

First, I select all rows whose 47th element is 2021:

list1 = Select[data,#[[47]]==2021 &];

Then I get the minimum value of all elements in column 89th in list1:

min=Min@list1[[All,89]];

Finally, I would like to display all rows in my original data whose 47th element is 2021 and 89th element is the above minimum:

Select[data,#[[47]]==2021 && #[[89]]==min &]

I don't really like this approach. My question: Do we have another better way to achieve the same result?

If the data has fewer columns like 3 or 4 then I found a solution using Cases. Can we use Cases in my case?

Jogn Bunda
  • 23
  • 3
  • Your approach is quite valid. May I ask why you want to change your current approach? Does it run slow, or is the solution resource intensive? In your last line of code, should it be >=min ? – Syed Oct 02 '21 at 09:27
  • @Syed Hi, it is {=}. I felt like going around too much in my approach. – Jogn Bunda Oct 02 '21 at 09:34
  • Would you share the solution you found with Cases with fewer columns. Why can it not be extended? – Syed Oct 02 '21 at 10:01
  • Here it is: https://mathematica.stackexchange.com/questions/10143/how-to-pick-an-element-of-a-row-corresponding-to-the-minimum-in-a-particular-col#answer-10147 – Jogn Bunda Oct 02 '21 at 10:16
  • In your post you say "89th element is above minimum" and yet you use == sign to extract such elements? I think I will let some experienced contributor edit your post with all the relevant information that is slowly coming together. In your title you use the word "effectively". Effective may mean more lines to impress someone, or a one liner to enter a codegolf competition. It may also mean fast performance or better parallel performance. Since you have used this word, you need to clarify what it exactly means before your question can be answered. – Syed Oct 02 '21 at 10:21
  • "the above minimum" not "above the minimum". I meant it is exactly the minimum mentioned above. To be effective, I meant to get another solution that gives the same output but saves time with less coding.

    My problem with Cases is that we need to declare the pattern first. So with 100 columns, it's not a good way.

    – Jogn Bunda Oct 02 '21 at 10:35
  • 3
    Does: MinimalBy[#[[89]] &] @ Select[#[[47]] == 2021 &] @ data do what you want? – Carl Woll Oct 02 '21 at 14:33
  • @Carl Your answer is the one that I am looking for. – Jogn Bunda Oct 03 '21 at 08:47

0 Answers0