median

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

99封情书 提交于 2019-12-04 04:34:07
问题 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. 回答1: Using ylim restricts the scale for y . In ggplot, data that falls outside the scale's

Replacing NA's in each column of matrix with the median of that column

只谈情不闲聊 提交于 2019-12-04 03:56:52
问题 I am trying to replace the NA's in each column of a matrix with the median of of that column, however when I try to use lapply or sapply I get an error; the code works when I use a for-loop and when I change one column at a time, what am I doing wrong? Example: set.seed(1928) mat <- matrix(rnorm(100*110), ncol = 110) mat[sample(1:length(mat), 700, replace = FALSE)] <- NA mat1 <- mat2 <- mat mat1 <- lapply(mat1, function(n) { mat1[is.na(mat1[,n]),n] <- median(mat1[,n], na.rm = TRUE) } ) for (n

Find the median of an unsorted array without sorting [duplicate]

ε祈祈猫儿з 提交于 2019-12-03 20:16:36
This question already has answers here : Closed 3 years ago . O(n) algorithm to find the median of a collection of numbers (3 answers) is there a way to find the Median of an unsorted array: 1- without sorting it. 2- without using the select algorithm, nor the median of medians I found a lot of other questions similar to mine. But the solutions, most of them, if not all of them, discussed the SelectProblem and the MedianOfMedians You can certainly find the median of an array without sorting it. What is not easy is doing that efficiently. For example, you could just iterate over the elements of

Minimum no. of comparisons to find median of 3 numbers

别来无恙 提交于 2019-12-03 15:54:28
问题 I was implementing quicksort and I wished to set the pivot to be the median or three numbers. The three numbers being the first element, the middle element, and the last element. Could I possibly find the median in less no. of comparisons? median(int a[], int p, int r) { int m = (p+r)/2; if(a[p] < a[m]) { if(a[p] >= a[r]) return a[p]; else if(a[m] < a[r]) return a[m]; } else { if(a[p] < a[r]) return a[p]; else if(a[m] >= a[r]) return a[m]; } return a[r]; } 回答1: You can't do it in one, and you

Median selection in CUDA kernel

倖福魔咒の 提交于 2019-12-03 15:18:18
问题 I need to compute the median of an array of size p inside a CUDA kernel (in my case, p is small e.g. p = 10). I am using an O(p^2) algorithm for its simplicity, but at the cost of time performance. Is there a "function" to find the median efficiently that I can call inside a CUDA kernel? I know I could implement a selection algorithm, but I'm looking for a function and/or tested code. Thanks! 回答1: Here are a few hints: Use a better selection algorithm: QuickSelect is a faster version of

Using MEDIAN along side MAX, MIN, and AVG functions in MySQL

只谈情不闲聊 提交于 2019-12-03 14:39:30
I have the following MySQL query which is working perfectly: select count(*) as `# of Data points`, name, max((QNTY_Sell/QNTYDelivered)*1000) as `MAX Thousand Price`, min((QNTY_Sell/QNTYDelivered)*1000) as `MIN Thousand Price`, avg((QNTY_Sell/QNTYDelivered)*1000) as `MEAN Thousand Price` from table_name where year(date) >= 2012 and name like "%the_name%" and QNTYDelivered > 0 and QNTY_Sell > 0 group by name order by name; Now I wish to also add a result column that gives me the MEDIAN of the data for each line. Under SELECT this would look like this in a perfect world: median((QNTY_Sell

find median in a fixed-size moving window along a long sequence of data

自古美人都是妖i 提交于 2019-12-03 10:20:14
问题 Given a sequence of data (it may have duplicates), a fixed-sized moving window, move the window at each iteration from the start of the data sequence, such that (1) the oldest data element is removed from the window and a new data element is pushed into the window (2) find the median of the data inside the window at each moving. The following posts are not helpful. Effectively to find the median value of a random sequence joining data based on a moving time window in R My idea: Use 2 heaps to

Median Filter Super efficient implementation

喜欢而已 提交于 2019-12-03 10:09:13
问题 I am looking for a Ansi C implementation of a fast/efficient median filter. Any pointers? So far, I have found the following implementation, which is good but I am curious on faster ones. I only need for 1 dimension. 回答1: I needed to extract a signal from very noisy CPU consumption data. Here's the Jeff McClintock median filter... Initialize the average and median to zero, then for each sample 'inch' the median toward the input sample by a small increment. Eventually it will settle at a point

Median selection in CUDA kernel

女生的网名这么多〃 提交于 2019-12-03 05:06:52
I need to compute the median of an array of size p inside a CUDA kernel (in my case, p is small e.g. p = 10). I am using an O(p^2) algorithm for its simplicity, but at the cost of time performance. Is there a "function" to find the median efficiently that I can call inside a CUDA kernel? I know I could implement a selection algorithm, but I'm looking for a function and/or tested code. Thanks! Domi Here are a few hints: Use a better selection algorithm: QuickSelect is a faster version of QuickSort for selecting the kth element in an array. For compile-time-constant mask sizes, sorting networks

Calculating Median in Ruby

跟風遠走 提交于 2019-12-03 04:11:29
How do I calculate the median of an array of numbers using Ruby? I am a beginner and within the progress of my learning I am trying to stick to what has already been taught. Thus the other questions that I've found are beyond my scope. Here are my notes and my attempt: sort the array in ascending order. figure out if it is odd or even in length. if odd, divide the sorted array length +1 in half. That is the index of the median. Return this value. if even, find the middle two numbers of the sorted array and divide them in 1/2. Return this value. Finding the middle two numbers: divide the sorted