07-16-2009
Help with Median
Hi,
I know this question has been asked before, but I'd like to ask for some explanation rather than solution regarding finding median in unix.
I've got a simple one column file with over 2 million numbers and I need to find its median. The file looks like this:
0.123
0.235
0.890
0.000 etc (just plain numbers).
The solution that I've found in forum answers was:
1) find the number of lines with this code:
wc -l filename
In my case it is: 2543887
2) if the number is not even (like in my case) than the median can be found with this code:
cat filename| head -$2543887 | tail -1
My question is how head -2543887 is different to head -$2543887? What does the dollar sign do?
Many thanks in advance!
6 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hi!
i have a file like the attachement.
you can see on the last column, there is a marker from 1 to 64 for each time.
I'd like to have the median for each marker: i want to get a median every 128 values
the result is : for an hour and marker x, i have the median value
thank you for... (5 Replies)
Discussion started by: riderman
5 Replies
2. Shell Programming and Scripting
Is there a way in awk to compute the median of a set of numbers in a file in the following format.
34
67
78
100
23
45
67 (3 Replies)
Discussion started by: Lucky Ali
3 Replies
3. Shell Programming and Scripting
Hi All,
I have some data like below.
Step1,Param1,Param2,Param3
1,2,3,4
2,3,4,5
2,4,5,6
3,0,1,2
3,0,0,0
3,2,1,3
........
so on
Where I need to find the median(arithmetic) of each column from Param1...to..Param3 for each set of Step1 values.
(Sort each specific column, if the... (5 Replies)
Discussion started by: ks_reddy
5 Replies
4. Shell Programming and Scripting
Hi all,
plz help me with this, I want to to extract the duplicate rows (column 1) in a file which at least repeat 4 times. then I want to summarize them by getting the max , mean, median and min. The file is sorted by column 1, all the repeated rows appear together.
If number of elements is... (5 Replies)
Discussion started by: ritakadm
5 Replies
5. UNIX for Dummies Questions & Answers
I am trying to calculate the median of a column of numbers if they match an ID type on a different column. The input file has 3 columns. The column that has the ID is column 1 and the column with the values I'd like to find the median for is column 3. The file does not need to be sorted.
What I... (9 Replies)
Discussion started by: verse123
9 Replies
6. Shell Programming and Scripting
I use the following script to print the sum and how could I extend this to print medians instead? thanks
name s1 s2 s3 s4
g1 2 8 6 5
g1 5 7 9 9
g1 6 7 8 9
g2 8 8 8 8
g2 7 7 7 7
g2 10 10 10 10
g3 3 12 1 24
g3 5 5 24 48
g3 12 3 12 12
g3 2 3 3 3
output
name s1 s2 s3 s4
g1 5 7 8 9... (5 Replies)
Discussion started by: quincyjones
5 Replies
LEARN ABOUT DEBIAN
pgasetrealinitpercent
PGASetRealInitPercent(2) PGAPack PGASetRealInitPercent(2)
NAME
PGASetRealInitPercent - sets the upper and lower bounds for randomly initializing real-valued genes.
DESCRIPTION
For each gene these bounds define an interval from which the initial allele value is selected uniformly randomly. With this routine the
user specifies a median value and a percent offset for each allele.
INPUT PARAMETERS
ctx - context variable
median - an array containing the mean value of the interval
percent
- an array containing the percent offset to add and subtract to the median to define the interval
OUTPUT PARAMETERS
none
SYNOPSIS
#include "pgapack.h"
void PGASetRealInitPercent(ctx, median, percent)
PGAContext *ctx
double *median
double *percent
LOCATION
real.c
EXAMPLE
Set the initialization routines to select a value for each real-valued
gene i uniformly randomly from the interval [i-v,i+v], where $v = i/2$.
Assumes all strings are the same length.
PGAContext *ctx;
double *median, *percent;
int i, stringlen;
:
stringlen = PGAGetStringLength(ctx);
median = (double *) malloc(stringlen*sizeof(double));
percent = (double *) malloc(stringlen*sizeof(double));
for(i=0;i<stringlen;i++) {
median[i] = (double) i;
percent[i] = 0.5;
}
PGASetRealInitPercent(ctx, median, percent);
05/01/95 PGASetRealInitPercent(2)