Help with Median


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with Median
# 1  
Old 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!
# 2  
Old 07-16-2009
Code:
cat filename| head -$2543887 | tail -1

Is it a correct command? Did you try this?? and cant see any maths here to get the median. am confused.
# 3  
Old 07-16-2009
Yes, I've tried it and the answer was 0.0751, while typing just
cat filename | head -$254887 | tail -1 gives 9.9997. So, these two command lines do something different?

I'm new to Unix. Do you think what I found won't give me the median? What do you think I should use?

Many thanks!

---------- Post updated at 07:59 AM ---------- Previous update was at 07:56 AM ----------

sorry, I meant that typing
cat filename | head -2543887 |tail -1 gives 9.9997
So, typing it with or without the dollar sign gives different outputs...
# 4  
Old 07-16-2009
i did not knew this $ thing with head...
and for median, i think you need to do the statistcs part. I dont know the formula Smilie
# 5  
Old 07-16-2009
I don't follow, how the head|tail can calculate the median.
# 6  
Old 07-16-2009
Unofrtunately, I'm new to Unix and don't know how the head and tail can calculate the median, but I thought that the dollar sign is a trick. This is why I asked the question in the first place.
Does anyone know how to calculate the mean, then?

---------- Post updated at 08:14 AM ---------- Previous update was at 08:10 AM ----------

sorry, I meant how to calculate the median
# 7  
Old 07-16-2009
Google is your friend
 
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print median values of matrix -awk?

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

2. UNIX for Dummies Questions & Answers

Median calculator based on id match

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

3. Shell Programming and Scripting

Median and max of duplicate rows

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

4. Shell Programming and Scripting

Awk based script to find the median of all individual columns in a data file

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

5. Shell Programming and Scripting

Compute the median of a set of numbers with AWK?

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

6. Shell Programming and Scripting

awk to median

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
Login or Register to Ask a Question