Sponsored Content
Operating Systems HP-UX calculate average of multiple line data Post 302198347 by smacherla on Thursday 22nd of May 2008 06:09:50 PM
Old 05-22-2008
Java calculate average of multiple line data

I have a question as below and i need to write a shell or perl script for this query:My Input file looks like below

RNo Marks

12 50
15 70
18 80
12 40
13 55
18 88
13 75
12 78
15 88


I want to calculate the average based on RNo.

I need the Output as:

RNo Average

12 .....
13 .....
15 .....
18 ......
Please answer this query and send me the script.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

calculate average of column 2

Hi I have fakebook.csv as following: F1(current date) F2(popularity) F3(name of book) F4(release date of book) 2006-06-21,6860,"Harry Potter",2006-12-31 2006-06-22,,"Harry Potter",2006-12-31 2006-06-23,7120,"Harry Potter",2006-12-31 2006-06-24,,"Harry Potter",2006-12-31... (0 Replies)
Discussion started by: onthetopo
0 Replies

2. Programming

calculate average

I have a file which is 2 3 4 5 6 6 so i am writing program in C to calculate mean.. #include<stdio.h> #include<string.h> #include <math.h> double CALL mean(int n , double x) main (int argc, char **argv) { char Buf,SEQ; int i; double result = 0; FILE *fp; (3 Replies)
Discussion started by: cdfd123
3 Replies

3. Shell Programming and Scripting

calculate the average of time series data using AWK

Hi, I have two time series data (below) merged into a file. t1 and t2 are in unit of second I want to calculate the average of V1 every second and count how many times "1" in V2 is occur within a second Input File: t1 V1 t2 V2 10.000000... (5 Replies)
Discussion started by: nica
5 Replies

4. Shell Programming and Scripting

Calculate average time using a script

Hello, I'm hoping to get some help on calculating an average time from a list of times (hour:minute:second). Here's what my list looks like right now, it will grow (I can get the full date or change the formatting of this as well): 07:55:31 09:42:00 08:09:02 09:15:23 09:27:45 09:49:26... (4 Replies)
Discussion started by: jaredhanks
4 Replies

5. Shell Programming and Scripting

AWK novice - calculate the average

Hi, I have the following data in a file for example: P1 XXXXXXX.1 YYYYYYY.1 ZZZ.1 P1 XXXXXXX.2 YYYYYYY.2 ZZZ.2 P1 XXXXXXX.3 YYYYYYY.3 ZZZ.3 P1 XXXXXXX.4 YYYYYYY.4 ZZZ.4 P1 XXXXXXX.5 YYYYYYY.5 ZZZ.5 P1 XXXXXXX.6 YYYYYYY.6 ZZZ.6 P1 XXXXXXX.7 YYYYYYY.7 ZZZ.7 P1 XXXXXXX.8 YYYYYYY.8 ZZZ.8 P2... (6 Replies)
Discussion started by: alex2005
6 Replies

6. Shell Programming and Scripting

Calculate Average AWK

I want to calculate the average line by line of some files with several lines on them, the files are identical, just want to average the 3rd columns of those files.:wall: Example file: File 1 001 0.046 0.667267 001 0.047 0.672028 001 0.048 0.656025 001 0.049 ... (2 Replies)
Discussion started by: AriasFco
2 Replies

7. Shell Programming and Scripting

Calculate average for repeated ID within a data

I have an awk script that gives the following output: Average end-to-end transmission delay 2.7 to 5.7 is 0.635392 seconds Average end-to-end transmission delay 2.1 to 5.1 is 0.66272 seconds Average end-to-end transmission delay 2.1 to 5.1 is 0.691712 seconds Average end-to-end transmission... (4 Replies)
Discussion started by: ENG_MOHD
4 Replies

8. Shell Programming and Scripting

Average of multiple time-stamped data every half hour

Hi All, Thank you for reading through my post and helping me figure out how I would be able to perform this task. For example: I have a list of continuous output collected into a file in the format as seen below: Date...........Time........C....A......... B ==========================... (5 Replies)
Discussion started by: terrychen
5 Replies

9. Shell Programming and Scripting

Calculate Average time of one column

Hello dears, I have a log file with records like below and want to get a average of one column based on the search of one specific keyword. 2015-02-07 08:15:28 10.102.51.100 10.112.55.101 "kevin.c" POST ... (2 Replies)
Discussion started by: Newman
2 Replies

10. Shell Programming and Scripting

Calculate the average per block.

My old school way is a one liner. And will search for average from SAR, to get the data receive rate. But, I dont think it is practical or accurate,. Because it calculates to off peak hours. I am planning to change it. My cron runs every 30 mins. When my cron runs, and my time is 14:47pm,, it will... (1 Reply)
Discussion started by: invinzin21
1 Replies
Statistics::Basic::LeastSquareFit(3pm)			User Contributed Perl Documentation		    Statistics::Basic::LeastSquareFit(3pm)

NAME
Statistics::Basic::LeastSquareFit - find the least square fit for two lists SYNOPSIS
A machine to calculate the Least Square Fit of given vectors x and y. The module returns the alpha and beta filling this formula: $y = $beta * $x + $alpha for a given set of x and y co-ordinate pairs. Say you have the set of Cartesian coordinates: my @points = ( [1,1], [2,2], [3,3], [4,4] ); The simplest way to find the LSF is as follows: my $lsf = lsf()->set_size(int @points); $lsf->insert(@$_) for @points; Or this way: my $xv = vector( map {$_->[0]} @points ); my $yv = vector( map {$_->[1]} @points ); my $lsf = lsf($xv, $yv); And then either query the values or print them like so: print "The LSF for $xv and $yv: $lsf "; my ($yint, $slope) = my ($alpha, $beta) = $lsf->query; LSF is meant for finding a line of best fit. $beta is the slope of the line and $alpha is the y-offset. Suppose you want to draw the line. Use these to calculate the "x" for a given "y" or vice versa: my $y = $lsf->y_given_x( 7 ); my $x = $lsf->x_given_y( 7 ); (Note that "x_given_y()" can sometimes produce a divide-by-zero error since it has to divide by the $beta.) Create a 20 point "moving" LSF like so: use Statistics::Basic qw(:all nofill); my $sth = $dbh->prepare("select x,y from points where something"); my $len = 20; my $lsf = lsf()->set_size($len); $sth->execute or die $dbh->errstr; $sth->bind_columns( my ($x, $y) ) or die $dbh->errstr; my $count = $len; while( $sth->fetch ) { $lsf->insert( $x, $y ); if( defined( my ($yint, $slope) = $lsf->query ) { print "LSF: y= $slope*x + $yint "; } # This would also work: # print "$lsf " if $lsf->query_filled; } METHODS
This list of methods skips the methods inherited from Statistics::Basic::_TwoVectorBase (things like insert(), and ginsert()). new() Create a new Statistics::Basic::LeastSquareFit object. This function takes two arguments -- which can either be arrayrefs or Statistics::Basic::Vector objects. This function is called when the leastsquarefirt() shortcut-function is called. query() LSF is meant for finding a line of best fit. $beta is the slope of the line and $alpha is the y-offset. my ($alpha, $beta) = $lsf->query; y_given_x() Automatically calculate the y-value on the line for a given x-value. my $y = $lsf->y_given_x( 7 ); x_given_y() Automatically calculate the x-value on the line for a given y-value. my $x = $lsf->x_given_y( 7 ); "x_given_y()" can sometimes produce a divide-by-zero error since it has to divide by the $beta. This might be helpful: if( defined( my $x = eval { $lsf->x_given_y(7) } ) ) { warn "there is no x value for 7"; } else { print "x (given y=7): $x "; } query_vector1() Return the Statistics::Basic::Vector for the first vector used in the computation of alpha and beta. query_vector2() Return the Statistics::Basic::Vector object for the second vector used in the computation of alpha and beta. query_mean1() Returns the Statistics::Basic::Mean object for the first vector used in the computation of alpha and beta. query_variance1() Returns the Statistics::Basic::Variance object for the first vector used in the computation of alpha and beta. query_covariance() Returns the Statistics::Basic::Covariance object used in the computation of alpha and beta. OVERLOADS
This object is overloaded. It tries to return an appropriate string for the calculation, but raises an error in numeric context. In boolean context, this object is always true (even when empty). AUTHOR
Paul Miller "<jettero@cpan.org>" COPYRIGHT
Copyright 2012 Paul Miller -- Licensed under the LGPL SEE ALSO
perl(1), Statistics::Basic, Statistics::Basic::_TwoVectorBase, Statistics::Basic::Vector perl v5.14.2 2012-01-23 Statistics::Basic::LeastSquareFit(3pm)
All times are GMT -4. The time now is 05:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy