Sponsored Content
Full Discussion: Help with Median
Top Forums UNIX for Dummies Questions & Answers Help with Median Post 302334687 by zajtat on Thursday 16th of July 2009 08:05:39 AM
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!
 

6 More Discussions You Might Find Interesting

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

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

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

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

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

6. 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
simulation::montecarlo(n)				       Tcl Simulation Tools					 simulation::montecarlo(n)

__________________________________________________________________________________________________________________________________________________

NAME
simulation::montecarlo - Monte Carlo simulations SYNOPSIS
package require Tcl ?8.4? package require simulation::montecarlo 0.1 package require simulation::random package require math::statistics ::simulation::montecarlo::getOption keyword ::simulation::montecarlo::hasOption keyword ::simulation::montecarlo::setOption keyword value ::simulation::montecarlo::setTrialResult values ::simulation::montecarlo::setExpResult values ::simulation::montecarlo::getTrialResults ::simulation::montecarlo::getExpResult ::simulation::montecarlo::transposeData values ::simulation::montecarlo::integral2D ... ::simulation::montecarlo::singleExperiment args _________________________________________________________________ DESCRIPTION
The technique of Monte Carlo simulations is basically simple: o generate random values for one or more parameters. o evaluate the model of some system you are interested in and record the interesting results for each realisation of these parameters. o after a suitable number of such trials, deduce an overall characteristic of the model. You can think of a model of a network of computers, an ecosystem of some kind or in fact anything that can be quantitatively described and has some stochastic element in it. The package simulation::montecarlo offers a basic framework for such a modelling technique: # # MC experiments: # Determine the mean and median of a set of points and compare them # ::simulation::montecarlo::singleExperiment -init { package require math::statistics set prng [::simulation::random::prng_Normal 0.0 1.0] } -loop { set numbers {} for { set i 0 } { $i < [getOption samples] } { incr i } { lappend numbers [$prng] } set mean [::math::statistics::mean $numbers] set median [::math::statistics::median $numbers] ;# ? Exists? setTrialResult [list $mean $median] } -final { set result [getTrialResults] set means {} set medians {} foreach r $result { foreach {m M} $r break lappend means $m lappend medians $M } puts [getOption reportfile] "Correlation: [::math::statistics::corr $means $medians]" } -trials 100 -samples 10 -verbose 1 -columns {Mean Median} This example attemps to find out how well the median value and the mean value of a random set of numbers correlate. Sometimes a median value is a more robust characteristic than a mean value - especially if you have a statistical distribution with "fat" tails. PROCEDURES
The package defines the following auxiliary procedures: ::simulation::montecarlo::getOption keyword Get the value of an option given as part of the singeExperiment command. string keyword Given keyword (without leading minus) ::simulation::montecarlo::hasOption keyword Returns 1 if the option is available, 0 if not. string keyword Given keyword (without leading minus) ::simulation::montecarlo::setOption keyword value Set the value of the given option. string keyword Given keyword (without leading minus) string value (New) value for the option ::simulation::montecarlo::setTrialResult values Store the results of the trial for later analysis list values List of values to be stored ::simulation::montecarlo::setExpResult values Set the results of the entire experiment (typically used in the final phase). list values List of values to be stored ::simulation::montecarlo::getTrialResults Get the results of all individual trials for analysis (typically used in the final phase or after completion of the command). ::simulation::montecarlo::getExpResult Get the results of the entire experiment (typically used in the final phase or even after completion of the singleExperiment com- mand). ::simulation::montecarlo::transposeData values Interchange columns and rows of a list of lists and return the result. list values List of lists of values There are two main procedures: integral2D and singleExperiment. ::simulation::montecarlo::integral2D ... Integrate a function over a two-dimensional region using a Monte Carlo approach. Arguments PM ::simulation::montecarlo::singleExperiment args Iterate code over a number of trials and store the results. The iteration is gouverned by parameters given via a list of keyword- value pairs. int n List of keyword-value pairs, all of which are available during the execution via the getOption command. The singleExperiment command predefines the following options: o -init code: code to be run at start up o -loop body: body of code that defines the computation to be run time and again. The code should use setTrialResult to store the results of each trial (typically a list of numbers, but the interpretation is up to the implementation). Note: Required keyword. o -final code: code to be run at the end o -trials n: number of trials in the experiment (required) o -reportfile file: opened file to send the output to (default: stdout) o -verbose: write the intermediate results (1) or not (0) (default: 0) o -analysis proc: either "none" (no automatic analysis), standard (basic statistics of the trial results and a correlation matrix) or the name of a procedure that will take care of the analysis. o -columns list: list of column names, useful for verbose output and the analysis Any other options can be used via the getOption procedure in the body. TIPS
The procedure singleExperiment works by constructing a temporary procedure that does the actual work. It loops for the given number of tri- als. As it constructs a temporary procedure, local variables defined at the start continue to exist in the loop. KEYWORDS
math, montecarlo simulation, stochastic modelling COPYRIGHT
Copyright (c) 2008 Arjen Markus <arjenmarkus@users.sourceforge.net> simulation 0.1 simulation::montecarlo(n)
All times are GMT -4. The time now is 10:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy