median

Compute median of up to 5 in Scala

﹥>﹥吖頭↗ 提交于 2019-12-02 02:31:03
问题 So, while answering some other question I stumbled upon the necessity of computing the median of 5. Now, there's a similar question in another language, but I want a Scala algorithm for it, and I'm not sure I'm happy with mine. 回答1: Here's an immutable Scala version that has the minimum number of compares (6) and doesn't look too ugly: def med5(five: (Int,Int,Int,Int,Int)) = { // Return a sorted tuple (one compare) def order(a: Int, b: Int) = if (a<b) (a,b) else (b,a) // Given two self-sorted

Matlab, comparing array using if statement

ぐ巨炮叔叔 提交于 2019-12-01 22:14:14
问题 I have searched the net trying to find an answer to this problem I have. I have an array much like the following A = [2 4 6 8 ; 3 5 7 9 ; 1 4 6 9] row median = [ 5 6 5 ] col median = [ 2 4 6 9 ] From these values I want to create a median map. So I have created the array MedianMap = int8(zeros(MAX_ROWS, MAX_COLS)) Within this array I want to assign three different values: 1, 0, -1. So the median map output will be of the same size of array 'A': if the value is greater than both the row and

ggplot2: does boxplot use for calculations only values lying within limits of y-axis?

人盡茶涼 提交于 2019-12-01 20:47:01
I noticed that median of boxplot (constructed with restricted ylim-parameter) may differ from the median obtained by median()-function or boxplot without adjusted y-axis. Does it mean that boxplot use for calculations only values lying within defined interval of y-axis?? And if so, how could I get correct boxplot (based on all values), but plot it on particular interval of y.axis?? Thank you very much. Using ylim restricts the scale for y . In ggplot, data that falls outside the scale's limits is discarded and is not included in any statistical computations (such as boxplots). To just zoom the

comparing numbers to sort then get median value

ⅰ亾dé卋堺 提交于 2019-12-01 19:54:56
Sorting five integers using bitwise or comparison operators can be achieved by first getting the highest number then the second highest then the third and so on. Here is my code in getting the highest number: #include <stdio.h> int main() { int a, b, c, d, e; int aa, bb, cc, dd, ee; a = 4; b = 2; c = 5; d = 1; e = 3; aa = (a > b) ? ((a > c) ? ((a > d) ? ((a > e) ? a : e) : ((d > e) ? d : e)) : ((c > d) ? ((c > e) ? c : e) : ((d > e) ? d : e))) : ((b > c) ? ((b > d) ? ((b > e) ? b : e) : ((d > e) ? d : e)) : ((c > d) ? ((c > e) ? c : e) : ((d > e) ? d : e))); printf("highest: %d\n", aa); return

Matlab, comparing array using if statement

╄→尐↘猪︶ㄣ 提交于 2019-12-01 18:46:54
I have searched the net trying to find an answer to this problem I have. I have an array much like the following A = [2 4 6 8 ; 3 5 7 9 ; 1 4 6 9] row median = [ 5 6 5 ] col median = [ 2 4 6 9 ] From these values I want to create a median map. So I have created the array MedianMap = int8(zeros(MAX_ROWS, MAX_COLS)) Within this array I want to assign three different values: 1, 0, -1. So the median map output will be of the same size of array 'A': if the value is greater than both the row and column median a "1" is assigned to the median map if the value is less than both the row and column

Finding the median value from a List of objects using Java 8

你离开我真会死。 提交于 2019-12-01 17:25:23
I have two classes that are structured like this: public class Company { private List<Person> person; ... public List<Person> getPerson() { return person; } ... } public class Person { private Double age; ... public Double getAge() { return age; } ... } Basically the Company class has a List of Person objects, and each Person object can get an Age value. If I get the List of the Person objects, is there a good way to use Java 8 to find the median Age value among all the Person objects (Stream doesn't support median but is there anything else)? Double medianAge; if(!company.getPerson().isEmpty)

Use mean in ggplot boxplots instead of median

社会主义新天地 提交于 2019-12-01 14:53:03
Is it possible to use the mean in a ggplot boxplot instead of the median? Reason I ask is that in my data the median = 0.0 and mean = 0.40 and I am interested in the mean. From the help ?geom_boxplot : library(ggplot2) # It's possible to draw a boxplot with your own computations if you # use stat = "identity": y <- rnorm(100) df <- data.frame( x = 1, y0 = min(y), y25 = quantile(y, 0.25), y50 = median(y), # <=== replace by mean y75 = quantile(y, 0.75), y100 = max(y) ) ggplot(df, aes(x)) + geom_boxplot( aes(ymin = y0, lower = y25, middle = y50, upper = y75, ymax = y100), stat = "identity" ) So

Use mean in ggplot boxplots instead of median

て烟熏妆下的殇ゞ 提交于 2019-12-01 13:34:27
问题 Is it possible to use the mean in a ggplot boxplot instead of the median? Reason I ask is that in my data the median = 0.0 and mean = 0.40 and I am interested in the mean. 回答1: From the help ?geom_boxplot : library(ggplot2) # It's possible to draw a boxplot with your own computations if you # use stat = "identity": y <- rnorm(100) df <- data.frame( x = 1, y0 = min(y), y25 = quantile(y, 0.25), y50 = median(y), # <=== replace by mean y75 = quantile(y, 0.75), y100 = max(y) ) ggplot(df, aes(x)) +

Find median in binary search tree

倖福魔咒の 提交于 2019-12-01 04:34:50
Write the implementation of the function T ComputeMedian() const that computes the median value in the tree in O(n) time. Assume that the tree is a BST but is not necessarily balanced. Recall that the median of n numbers is defined as follows: If n is odd, the median is x such that the number of values smaller than x is equal to the number of values greater than x. If n is even, then one plus the number of values smaller than x is equal to the number of values greater than x. For example, given the numbers 8, 7, 2, 5, 9, the median is 7, because there are two values smaller than 7 and two

Conditional median in MS Excel

南笙酒味 提交于 2019-12-01 03:13:36
I'm trying to calculate the conditional median of a chart that looks like this: A | B ------- x | 1 x | 1 x | 3 x | y | 4 z | 5 I'm using MS Excel 2007. I am aware of the AVERAGEIF() statement, but there is no equivalent for Median. The main trick is that there are rows with no data - such as the 4th "a" above. In this case, I don't want this row considered at all in the calculations. Googling has suggested the following, but Excel won't accept the formula format (maybe because it's 2007?) =MEDIAN(IF((A:A="x")*(A:A<>"")), B:B) Excel gives an error saying there is something wrong with my