min

which.max ties method in R

怎甘沉沦 提交于 2019-12-21 03:42:44
问题 which.max and which.min will return the smallest index of the max or min value if there are ties. Is there a way around this so that the largest index is returned without affecting the efficiency of the function? max.col has this exact functionality, but I am dealing with a vector not a matrix. 回答1: You could do like this: x<-c(1,2,1,4,3,4) #identical to which.max, except returns all indices with max which(x==max(x)) [1] 4 6 z<-which(x==max(x)) z[length(z)] [1] 6 #or with tail tail(which(x=

Find min value in array > 0

天大地大妈咪最大 提交于 2019-12-20 18:58:09
问题 I am looking to find the lowest positive value in an array and its position in the list. If a value within the list is duplicated, only the FIRST instance is of interest. This is what I have which does what I want but includes 0. print "Position:", myArray.index(min(myArray)) print "Value:", min(myArray) for example, as it stands if, myArray = [4, 8, 0, 1, 5] then Position: 2, Value: 0 I want it to present position: 3, value: 1 回答1: You can use a generator expression with min . This will set

Sort by minimum value of two columns

冷暖自知 提交于 2019-12-20 10:26:20
问题 I use SQL Server 2008 R2 . I need to sort a table by the minimal value of two columns. The table looks like this: ID: integer; Date1: datetime; Date2: datetime. I want my data to be sorted by minimal of two dates. What is the simplest way to sort this table that way? 回答1: NOT NULL columns . You need to add CASE statement into ORDER BY clause in following: SELECT Id, Date1, Date2 FROM YourTable ORDER BY CASE WHEN Date1 < Date2 THEN Date1 ELSE Date2 END NULLABLE columns . As Zohar Peled wrote

Finding the minimum value of int numbers in an array (Java)

荒凉一梦 提交于 2019-12-20 05:53:25
问题 I'm trying to find the minimum value of numbers in an array but it doesn't always work out properly. This is the code I wrote: for (int i=0; i < arr.length; i++ ) { min = arr[i]; for (j=0; j < arr.length; j++) { if (arr[j] < arr[0]) { min = arr[j]; } } } Can someone correct me please? 回答1: There's no need for the outer loop, it only runs once and you don't use i anyway. why do you have it? For the inner loop, you need to compare against the minimum value. Right now you are comparing it

Finding common minimum value between two arrays

白昼怎懂夜的黑 提交于 2019-12-19 04:50:18
问题 I am working on a problem in Javascript. Finding common minimum value between two arrays. However, I have been told that this might not work on some values. What is the issue? function cmp(a, b) { return a - b; } function findMinimum(A, B) { var n = A.length; var m = B.length; A.sort(cmp); B.sort(cmp); var i = 0; for (var k = 0; k < n; k++) { if (i < m - 1 && B[i] < A[k]) i += 1; if (A[k] == B[i]) return A[k]; } return -1; } 回答1: Let's take, A = [ 1, 3, 5, 7] B = [ 0, 0, 1, 4, 6] and run

R: Distributing an amount as evenly as possible II

℡╲_俬逩灬. 提交于 2019-12-19 04:50:14
问题 We have have a certain amount e.g. 300 units. This amount should be as evenly as possible distributed over 40 "slots" or "bins". It would be easy if each slot would be the same - so it would be 7,5 at each slot. However, the slots vary in size and we cannot "fill in" there more than its "size" allows for e.g. if its only 4. What we cannot "fill in" more than 4. Hence, we have to distribute more over the other ones. Lets assume that there is another limitation: A general filling in limit of e

Making javax validation error message more specific

回眸只為那壹抹淺笑 提交于 2019-12-18 13:05:24
问题 Sorry if this question has been covered somewhere before. If it has please link me to it, I haven't been able to find a satisfactory answer as yet. I've been looking around trying to find a way to have the error messages provided by my javax validation more specific. The message I currently have for my @Min annotation is specified in the ValidationMessages.properties file: javax.validation.constraints.Min.message=The value of this variable must be less than {value}. and this prints out as

Why Math.min() > Math.max()?

六月ゝ 毕业季﹏ 提交于 2019-12-18 10:48:29
问题 When I type in an array into the parameter of the javascript math minimum and maximum functions, it returns the correct value: console.log( Math.min( 5 ) ); // 5 console.log( Math.max( 2 ) ); // 2 var array = [3, 6, 1, 5, 0, -2, 3]; var minArray = Math.min( array ); // -2 var maxArray = Math.max( array ); // 6 However, when I use the function with no parameters, it returns an incorrect answer: console.log( Math.min() ); // Infinity console.log( Math.max() ); // -Infinity This one returns

Get the minimum value between several columns

一世执手 提交于 2019-12-18 08:10:12
问题 I'm using SQL Server 2008; Suppose I have a table 'X' with columns 'Date1', 'Date2', 'Dateblah', all of type DateTime. I want to select the min value between the three columns, for example (simplified, with date mm/dd/yyyy) ID Date1 Date2 Dateblah 0 09/29/2011 09/20/2011 09/01/2011 1 01/01/2011 01/05/2011 03/03/2010 ID MinDate 0 09/01/2011 1 03/03/2010 Is there a bread and butter command to do that ? Thanks in advance. EDIT: I've seen this question What's the best way to select the minimum

std::max() and std::min() not constexpr

故事扮演 提交于 2019-12-18 05:27:07
问题 I just noticed that the new standard defines min(a,b) and max(a,b) without constexpr . Examples from 25.4.7, [alg.min.max]: template<class T> const T& min(const T& a, const T& b); template<class T> T min(initializer_list<T> t); Isn't this a pity? I would have liked to write char data[ max(sizeof(A),sizeof(B)) ]; instead of char data[ sizeof(A) > sizeof(B) ? sizeof(A) : sizeof(B) ]; char data[ MAX(sizeof(A),sizeof(B)) ]; // using a macro Any reason why those can not be constexpr ? 回答1: