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();
7849 questions
2
votes
5 answers

Find the most recent date in a result set

I'm working on a query where I need to look at patient vitals (specifically blood pressure) that were entered when a patient visited a clinic. I'm pulling results for the entire year of 2015, and of course there are certain patients who visited…
EJF
  • 353
  • 3
  • 6
  • 20
2
votes
2 answers

VBA How to find closest number

I have a range (which changes at certain intervals). For each change, I would like to find the numbers in the range that are closest to 0.5, both on the upside and on the downside. So, for instance, if I have: 0.42 0.48 0.51 0.53 I would like to…
Gram
  • 127
  • 1
  • 9
2
votes
1 answer

D3 : best way to find max value in a JSON object

What's the best way to find the maximum value of n2 (450) in this dataJSON3 object using d3.js? var dataJSON3 = { set1 : [ {"nom":"Allemagne", "n1":200, "n2":86, "n3": 30}, {"nom":"Allemagne", "n1":120, "n2":156, "n3": 40}, …
Le Sparte
  • 153
  • 1
  • 11
2
votes
4 answers

How to get the MAX(Hour) and The MIN(Hour) for each day in this query?

I have this structure of table Diary: CREATE TABLE Diary ( [IdDiary] bigint, [IdDay] numeric(18,0) ); INSERT INTO Diary ([IdDiary], [IdDay]) values (51, 1), (52, 2), (53, 5); And this other structure for table DiaryTimetable: CREATE…
Esraa_92
  • 1,481
  • 1
  • 15
  • 43
2
votes
7 answers

How do I collect multiple maximum values from a List

How to get max from an ArrayList that has more than one max? For example, if an ArrrayList contains max = 20 stored at index 2, 3 and 6, how do you get all that indicies?
Ongchu Sherpa
  • 91
  • 2
  • 7
2
votes
1 answer

what is the max size of TextProperty on google app engine

class JsTree_JsonData(db.Model): JsonData=db.TextProperty() i can;t find what is the TextProperty did you know ? thanks
zjm1126
  • 30,692
  • 52
  • 112
  • 161
2
votes
1 answer

Is there a Objective-C or C math function to constrain a variable between a Min and a Max?

What I am looking for is a math function that constrains a primitive variable between a minimum and a maximum value in only one single function call, if it exists, in the standard math libraries for Objective-C. I currently use: float…
2
votes
1 answer

Get maximum value from a range based on a criteria that is dynamic

So I have this spreadsheet where I'd like to extract the maximum value (last date) from a table range, but based on a criteria from a specific column in the table range. Initially I thought a nested MAX function and within it a VLOOKUP but soon…
Marcus Draven
  • 21
  • 1
  • 3
2
votes
2 answers

Finding the highest value

So I'm currently using a loop to search through my csv data to find the "high" and "low" values of a group of days and then calculate the averages of each day. With those averages, I want to find the highest one amongst them but I've been having…
DLiu456
  • 25
  • 2
2
votes
2 answers

Max value in a for loop python

I've been trying to figure out how to print the maximum value from a for loop. It's required for my homework assignment. I've tried using the max function but I keep getting TypeError: unorderable types: str() > float(). for NP in range(MP, MaxP+1,…
2
votes
2 answers

Maximum value in a column

Is there a more efficient way to do this? I want the maximum value of a column (int) in a given MySQL table using PHP. $results = $conn->query("SELECT statement_id FROM statement ORDER BY statement_id DESC LIMIT 1"); $next_statment_id =…
Mark
  • 394
  • 4
  • 17
2
votes
1 answer

Getting 2d array maximum in a more Rubyish way?

Background: In Ruby I have a 2d array like the following: count[[english_word, french_word]] = ... pp count {["my", "une"]=>0.0, ["my", "voiture"]=>0.2, ["red", "maison"]=>0.9, ... } (The reason I did this rather than…
Ben Humphreys
  • 5,629
  • 5
  • 30
  • 46
2
votes
4 answers

Max number from a set of data

I want to get the maximum value of three consecutive numbers using the data below, starting with the first three numbers in this case 50.0, 50.0 and 42.8 then store it in another Nx1 matrix, then pick the second next three numbers, 50.0, 42.8 and…
Kola
  • 77
  • 6
2
votes
0 answers

Mongorestore max file size

After mongodump my database is 3.08 Gb. I have a lot of bson-files bigger than 100 Mb and even 1 file more than 1 Gb. After mongorestore I'm receiving following error: SocketException: remote: 127.0.0.1:27017 error: 9001 socket excep …
mrVG
  • 45
  • 7
2
votes
2 answers

Python max() function doesnt give correct results when two strings are compared

I am new to Python. The task in hand is to find the latest build in a list of builds in a particular directory. My code looks like this: command = 'ls ' + self.build_path stdin, stdout, stderr = self.ssh.exec_command(command) builds_list…
Rajive Pai
  • 192
  • 11
1 2 3
99
100