0
$\begingroup$

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?

$\endgroup$
8
  • $\begingroup$ 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 ? $\endgroup$ Commented Oct 2, 2021 at 9:27
  • $\begingroup$ @Syed Hi, it is {=}. I felt like going around too much in my approach. $\endgroup$ Commented Oct 2, 2021 at 9:34
  • $\begingroup$ Would you share the solution you found with Cases with fewer columns. Why can it not be extended? $\endgroup$ Commented Oct 2, 2021 at 10:01
  • $\begingroup$ Here it is: mathematica.stackexchange.com/questions/10143/… $\endgroup$ Commented Oct 2, 2021 at 10:16
  • 3
    $\begingroup$ Does: MinimalBy[#[[89]] &] @ Select[#[[47]] == 2021 &] @ data do what you want? $\endgroup$ Commented Oct 2, 2021 at 14:33

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.