Questions tagged [max]

Maximum value. Largest, biggest, greatest.

max

max() is a math library function available in many programming environments which returns the entity of greatest value from two or more candidate values.

Do not use for questions about the maximal value of a type, e.g. Long.MAX_VALUE, Integer.MAX_VALUE, etc.

Examples

SQL

SQL MAX() function is one of aggregate functions. It returns the largest value of column.

SELECT MAX(column_name) FROM table_name;

Python

In Python, the native max function identifies the largest element of a set (e.g. a list).

>> max([1, 2, 3])
3

Java

In Java we can use java.lang.Math class to compute maximum value of two arguments.

int maxElement = Math.max(x, y);

To compute maximum element in collection we can use, max() method from java.util.Collections class.

int maxElement = Collections.max(list);

Ruby

In Ruby to compute maximum element of collection we simply use max function.

[4,7].max

Clojure

In Clojure we use max function in the following way.

(max 1 2 3 4)

In above code max is the function name and numbers 1..4 are arguments passed to it. We can also apply the max function to lists.

(apply max [1 2 3 4])

R

In R we have function max.

x <- c(1, 2, 3)
y <- c(4, 5)
z <- c(6, NA)
max(x)
max(y)
max(z)
max(z, na.rm = TRUE)
max(x, y, z, na.rm = TRUE)  ## as same as max(c(x, y, z), na.rm = TRUE)

Rust

In Rust we can use std::cmp::max to compute the maximum value of two arguments.

let max = std::cmp::max(x, y);

We can compute the maximum element in a collection by transforming it into an Iterator and then calling the max method on the iterator.

let max = collection.into_iter().max();
8982 questions
2
votes
2 answers

Create function which returns the row name and the maximum value

I have two different data frames df <- data.frame(A=c(3,2,1,4,5),B=c(1,6,3,8,4),C=c(2,1,4,8,9), D=c(4,1,2,4,6), Type=c("M","M","N","J","M")) row.names(df)<-c("R1","R2","R3","R4","R5") A B C D Type R1 3 1 2 4…
Joe
  • 181
  • 7
2
votes
5 answers

Function that returns three highest value in row in R

I have two sets of data frames and I am trying to create a function which takes in a data frame and row name as an argument and returns the three highest value on the row (in a descending order) and the name of the column of three highest value. …
Joe
  • 181
  • 7
2
votes
4 answers

How to find the top several values from an array?

I have an array of float values and want the value and more importantly the position of the maximum four values. I built the system originally to walk through the array and find the max the usual way, by comparing the value at the current position…
Karl
  • 8,967
  • 5
  • 29
  • 31
2
votes
3 answers

How to get max value of a date field in a large json file?

I have a large JSON file around 500MB which is the response of a URL call.I need to get the max value of "date" field in the JSON file in the "results" array using shell script(bash).Currently using jq as below.Below works good for smaller files but…
SimpleBI
  • 23
  • 4
2
votes
2 answers

Find the maximum of three integers

I have made a program for finding the greatest of the given three numbers. It works for single digit but it is not working for three digit numbers. Why not? package practice; import java.util.Scanner; public class AllPractice { public static…
2
votes
3 answers

Formula to find max & min of string if sort alphabetical

if I have a list of string like '0401 A', '0319 B' '0801 C' and they appears in different columns and rows in an excel sheet, what is the formula to get the max & min of these strings. In this case, max and min would be '0801 C' and '0319 B' if its…
2
votes
1 answer

How to set maximum width for Gridview's BouldField Column?

I have a design flaw and in a desperate need for a help because I am fairly new with .NET. I have a GridView on my page and my goal is to limit the maximum width for each column. Below is the code:
Sammm
  • 501
  • 4
  • 9
  • 25
2
votes
1 answer

How can I specify the objective in a CP-SAT formulation (in python) to be the minimization of the max of all decision variable values?

I am attempting to implement a simple CP-SAT where the objective is to minimize the largest value assigned across all decision variables. I can minimize any individual variable or a linear function of variables, but it seems I am unable to minimize…
2
votes
1 answer

How to find the max of each row in a table in MYSQL

I have this table below which has N rows. here i simplify it to 3 rows. Example Table A B C D 5.640700669769904 5.623475843268976 5.644739934022418 5.62489798487818 …
AndiAna
  • 854
  • 6
  • 26
2
votes
3 answers

Combining MIN and MAX into a rowise function in R

I have a bit of code that I used in an excel spreadsheet that used min and max that I'm trying to transfer over to R. I have two columns, "mini" and "maxi" which represent a range of possible values. The third column I'm trying to populate is the…
Corey
  • 405
  • 2
  • 6
  • 18
2
votes
4 answers

Finding multiple max elements in a vector C++

So.. I am trying to find the maximum value of a vector and its position in the vector. I am using a for loop, and it's working fine. My problem is, that if the maximum value appears more than once, I want to know all the positions in which it…
2
votes
2 answers

Finding the maximum in a Numpy array every nth instance

I have a large file with wind speed and direction every second. I have stored each element into a numpy array. The wind speeds for example are ws=(7, 8, 8.5, 8, 9.5). I would like to fill another array with the maximum 1 minute wind speed, so every…
Jonathon
  • 251
  • 1
  • 7
  • 20
2
votes
2 answers

Dataset with maximal rows by userId indicated

I have a dataframe like this: ID date var1 var2 var3 AB 22/03/2020 0 1 3 AB 29/03/2020 0 3 3 CD 22/03/2020 0 1 1 And I would like to have a new dataset that, if it is a maximal column (can happen ties too) leaves the…
Catarina Nogueira
  • 1,024
  • 2
  • 12
  • 28
2
votes
1 answer

Getting max value from dictionary and corresponding values

I have python script which is using google STT engine and then it loops through dictionary to check where is the biggest match (ratio) using difflib SequenceMatcher UPDATE (better explanation of what script needs to do): variable izgovoreno…
kish89
  • 23
  • 1
  • 3
2
votes
3 answers

max in a list of tuples (Python)

I have this list of list of tuples var1 = [ [(10, '♣'), (7, '♠')], [(14, '♣'), (2, '♣')], [(2, '♥'), (9, '♦')], [(11, '♠'), (10, '♠')], [(11, '♦'), (5, '♣')] ] and I wanna extract the tuple with the maximun value which is the…