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
1 answer

Extract Min and Max Value from the row value delimited by "#"

I have a Dataframe which contains columns, Col_1 Col_2 '0' '-33#90#' '-1#65#' '0' '90' '-22#-44#90#250' I want to get the min and max for the respective column values. I don't have any clue how to get that. My output should…
venkat
  • 1,203
  • 3
  • 16
  • 37
2
votes
1 answer

Divide by maximum within a group in pandas dataframe

I do have a dataframe below: cola colb a 10 a 12 a 30 b 20 b 25 I would like to add new column like: for each group find the maximum and then calculate newcol=(max(withingroupcola)-colb)/max(withingroupcola) within each…
melik
  • 1,268
  • 3
  • 21
  • 42
2
votes
3 answers

SQL Select with Join and last record needed

I've got the following tables: devices table SN tested_device_id test_setup_id 129 6 103 129 7 104 130 8 106 test_setup table test_setup_id data1 103 111 104 333 106 555 I want to deliver SN,…
Dave
  • 21
  • 1
2
votes
2 answers

random number generator being called when it shouldn't, i think

#include "std_lib_facilities.h" #include static float dx=0.0; static float dz=10; static float points[2]; static float cx=0.0; static float cy=0.0; static float cz=0.0; static float spin=0.0; static float rotation=1.0; int…
Darren
  • 61
  • 1
  • 7
2
votes
2 answers

Finding max value using AWK

I have a file with two column data and I want to find the max value and print it. file =load_measure 11:20,18.03 11:25,17.85 11:30,18.24 11:35,19.19 11:40,18.45 11:45,17.53 11:50,17.56 11:55,17.60 12:00,18.51 12:05,18.50 I try via hereunder code…
Dominik
  • 33
  • 4
2
votes
1 answer

Find if values are equal in datarow, by max and min value of string column

I have datarow with a few columns, some of them are string. I want to find the row with the maximum value in a string column. So first, Can I find a max between strings? (I need max and min for compere them and by this to find if all this column…
user11568901
2
votes
2 answers

Linq Max Value from ObservableCollection

I have an ObservableCollection with two properties string and int. I would like to query and return the int with the Max value. Data example: Category, WorkOrderVersion AAA 1 AAA 2 AAA 3 BBB 1 BBB 2 if Category == "BBB" I would want to return…
mjordan
  • 319
  • 2
  • 22
2
votes
3 answers

Return the maximum value of every subgroup in a table

I have a section of table like this: X Y Value __ __ __ 1 2 6.9 1 3 6.8 1 4 8.1 2 1 7.2 2 3 11.7 2 4 16 3 1 22.6 3 2 20.5 3 3 18.1 … … … For each group of rows…
jane
  • 567
  • 2
  • 12
2
votes
2 answers

HTML Input Time, where min is pm (late) and max is am (early)

I have an input box, with a type of "time". I want to have a late time (23:00pm) as a min value, and an early time (6:00am) as a max value - creating a range of 23pm - 6am. (ie. 11pm, 12pm, 1am, 2am, 3am, 4am, 5am, 6am). I've tried using Javascript,…
JCoulam
  • 181
  • 2
  • 13
2
votes
3 answers

Assign max value of group to all rows in that group

I would like to assign the max value of a group to all rows within that group. How do I do that? I have a dataframe containing the names of the group and the max number of credits that belongs to it. course_credits <-…
jtsbattle
  • 185
  • 1
  • 8
2
votes
0 answers

InfluxDB MAX value as time series

In InfluxDB, I have a time series of which I would like to determine the maximum value. Using the MAX() function does return the maximum, but as a single point consisting of the maximum value and corresponding timestamp. How can I get not just a…
John S.
  • 501
  • 2
  • 6
  • 17
2
votes
1 answer

How to find largest absolute value from specific columns for repetitive row elements using Pandas in Python and also display row and column index

I am new to python. I want to find the top 2 largest values from all the columns for repetitive row elements (i.e. 5 to 4100), and also show its respective row and column index label in output.The largest value should be absolute. (Irrespective of +…
axay
  • 437
  • 5
  • 19
2
votes
1 answer

Get all combinations that sum up to 274 and max value is up to 4 in R

I'd like to get every combination of 280 elements that sum 274, but every value must be an integer and between 0 and 4. There is a function that almost do this, that is restrictedparts (which i found here: Getting all combinations which sum up to…
2
votes
2 answers

Calculate a timedelta between rows as the difference between the maxium and the minimum time for each element of a second column

I would like to calculate the distribution of a an item based on how long does it take between the first and the last order of that item. To reach that goal though, first I have to get that time delta for each item. My initial dataframe has three…
rafspo
  • 143
  • 8
2
votes
1 answer

select distinct(col a) max(colb)

I have a table with data similar to: | col_a | col_b | |-------|----------| |left |01/01/2017| |left |02/02/2018| |left |03/03/2019| * |right |04/04/2017| |right |05/05/2018| |right |06/06/2019| * I am trying to extract data with the…
Tunna182
  • 343
  • 3
  • 16
1 2 3
99
100