median

Code to calculate "median of five" in C#

Note: Please don't interpret this as "homework question." This is just a thing I curious to know :) The median of five is sometimes used as an exercise in algorithm design and is known to be computable using only 6 comparisons. What is the best way to implement this "median of five using 6 comparisons" in C# ? All of my attempts seem t...

Best Way To Calculate A Median In Access 2007 When Using Group By

I have a table which contains a book and then multiple prices about the book (this is a highly simplified sample): ID BOOK PRICE 1 BOOK1 10 2 BOOK1 15 3 BOOK1 12 4 BOOK2 8 5 BOOK2 2 I am easily calculating the average, but there must be a nice way to calculate the median? Current SQL: SELECT DISTINCTROW Books.BOOK, Avg...

Conditional median in MS Excel

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 th...

Finding the median of numbers in a LinkedList

How do you find the median of a list of numbers stored as a LinkedList in Java? I don't understand the Selection Algorithm that Wikipedia refers to. Bonus points if you can explain that. ...

"On-line" (iterator) algorithms for estimating statistical median, mode, skewness, kurtosis?

Is there an algorithm to estimate the median, mode, skewness, and/or kurtosis of set of values, but that does NOT require storing all the values in memory at once? I'd like to calculate the basic statistics: mean: arithmetic average variance: average of squared deviations from the mean standard deviation: square root of the varianc...

DB2 SQL - median with GROUP BY

Hi everybody, First of all, I am running on DB2 for i5/OS V5R4. I have ROW_NUMBER(), RANK() and common table expressions. I do not have TOP n PERCENT or LIMIT OFFSET. The actual data set I'm working with is hard to explain, so let's just say I have a weather history table where the columns are (city, temperature, timestamp). I want ...

How to do median splits within factor levels in R?

Here I make a new column to indicate whether myData is above or below its median ### MedianSplits based on Whole Data #create some test data myDataFrame=data.frame(myData=runif(15),myFactor=rep(c("A","B","C"),5)) #create column showing median split myBreaks= quantile(myDataFrame$myData,c(0,.5,1)) myDataFrame$MedianSplitWholeData = cut...

Simple way to calculate median with MySQL

What's the simplest (and hopefully not too slow) way to calculate the median with MySQL? I've used AVG(x) for finding the mean, but I'm having a hard time finding a simple way of calculating the median. For now, I'm returning all the rows to PHP, doing a sort, and then picking the middle row, but surely there must be some simple way of d...

Rolling median algorithm in C

I am currently working on an algorithm to implement a rolling median filter (analogous to a rolling mean filter) in C. From my search of the literature, there appear to be two reasonably efficient ways to do it. The first is to sort the initial window of values, then perform a binary search to insert the new value and remove the exiting ...

Function to Calculate Median in Sql Server

According to MSDN, Median is not available as an aggregate function in Transact-Sql. However, I would like to find out whether it is possible to create this functionality (using the Create Aggregate function, user defined function, or some other method). What would be the best way (if possible) to do this - allow for the calculation of...

More efficient way to plot x-axis points?

I have been working on a project that requires a bar graph to be populated with price results. The chart displays the number of items within a given price range. For instance, if on amazon there are 9 items within the price range of $0-$10 the x-axis would display $0-$10 and the y-axis would be populated with a value of 9. My bar graph...

Memory-efficient way of computing the median of a large data set?

If one computer can only hold 1 million numbers, how to find out the median number from 100 million numbers? ...

How can I calculate the median and standard deviation of a bunch stream of numbers in Perl?

Hi everyone, In our logfiles we store response times for the requests. What's the most efficient way to calculate the median response time, the "75/90/95% of requests were served in less than N time" numbers etc? (I guess a variation of my question is: What's the best way to calculate the median and standard deviation of a bunch stre...

How to find k nearest neighbors to the median of n distinct numbers in O(n) time?

I can use the median of medians selection algorithm to find the median in O(n). Also, I know that after the algorithm is done, all the elements to the left of the median are less that the median and all the elements to the right are greater than the median. But how do I find the k nearest neighbors to the median in O(n) time? If the med...

Fastest way of finding the middle value of a triple?

I've got the following scenario: There are three ("pseudo" randomly chosen) int or float values which represent indices of an array. Now I'd like to compare the appropriate values from that array. After having compared them I'd like to know the middle value of the three and use this specific element for some further array operations. T...

given 5 numbers, what is the minimum number of comparisons needed to find the median?

how do you setup minimum number of comparisons in general? ...

how do you find the median of 2 columns using R ?

Hi , Im trying to compute the median vector of a data set s with column A1 and B1 , The median vector is the median for each observation from both columns. I tried to do this and it didnt work . median(s[c("A1","B1")]) Is there another way to do it ? ...

What is the right approach when using STL container for median calculation?

Let's say I need to retrieve the median from a sequence of 1000000 random numeric values. If using anything but STL::list, I have no (built-in) way to sort sequence for median calculation. If using STL::list, I can't randomly access values to retrieve middle (median) of sorted sequence. Is it better to implement sorting myself and go...

Median of Medians in Java

I am trying to implement Median of Medians in Java for a method like this: Select(Comparable[] list, int pos, int colSize, int colMed) list is a list of values of which to find a specified position pos is the specified position colSize is the size of the columns that I create in the first stage colMed is the position in those columns...

Compute Median of Values Stored In Vector - C++?

Hi there, I'm a programming student, and for a project I'm working on, on of the things I have to do is compute the median value of a vector of int values. I'm to do this using only the sort function from the STL and vector member functions such as .begin(), .end(), and .size(). I'm also supposed to make sure I find the median whether ...