Sponsored Content
Top Forums UNIX for Dummies Questions & Answers calculate average of column 2 Post 302125743 by onthetopo on Friday 6th of July 2007 08:16:22 PM
Old 07-06-2007
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
2006-06-25,7498,"Harry Potter",2006-12-31
2006-06-26,7500,"Harry Potter",2006-12-31
2006-06-27,7750,"Harry Potter",2006-12-31
2006-06-28,7860,"Harry Potter",2006-12-31
2006-06-29,,"Harry Potter",2006-12-31
2006-06-30,7860,"Harry Potter",2006-12-31
2006-07-01,1760,"Bible",2007-03-03
2006-07-02,2755,"Bible",2007-03-03
2006-07-03,3760,"Bible",2007-03-03
2006-07-04,,"Bible",2007-03-03
2006-07-05,5788,"Bible",2007-03-03
2006-07-06,6799,"Bible",2007-03-03
...............................

I want to add a new column in each line that is Field 5 (average popularity[over a sample of three days] 6 months before release date)

So for the harry potter book, the release date is 2006-12-31, I need to find the average value of field 2 over the following date points: 2006-06-30,2006-06-28 and 2006-06-27. (This problem is complicated by the fact that the popularity of 2006-06-29 is unavailable and left as blank in the csv, so 2006-06-29 is skipped in the calculation of average).

My supervisor gave me a short timespan to solve this.I've already got the datecalc script found in FAQ but haven't found its use in my context yet. Can someone please help me? Thanks a million!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Use awk to calculate average of column 3

Suppose I have 500 files in a directory and I need to Use awk to calculate average of column 3 for each of the file, how would I do that? (6 Replies)
Discussion started by: grossgermany
6 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 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

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

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

6. Shell Programming and Scripting

Calculate the average of a column based on the value of another column

Hi, I would like to calculate the average of column 'y' based on the value of column 'pos'. For example, here is file1 id pos y c 11 1 220 aa 11 4333 207 f 11 5333 112 ee 11 11116 305 e 11 11117 310 r 11 22228 781 gg 11 ... (2 Replies)
Discussion started by: jackken007
2 Replies

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

8. Shell Programming and Scripting

Match first two columns and calculate percent of average in third column

I have the need to match the first two columns and when they match, calculate the percent of average for the third columns. The following awk script does not give me the expected results. awk 'NR==FNR {T=$3; next} $1,$2 in T {P=T/$3*100; printf "%s %s %.0f\n", $1, $2, (P>=0)?P:-P}' diff.file... (1 Reply)
Discussion started by: ncwxpanther
1 Replies

9. Shell Programming and Scripting

Calculate average, azimut and distance

Gents, Please i will to get the distance and azimut from 2 coordinates: Usig excel formula i get the correct values, but i will like to do it using awk. Example A 35089.0 50345.016 9 75 1 2101774 77 70 79 483911.6 2380106.9 137.4 1 1 6 1 A 35089.0 50345.01620 75... (8 Replies)
Discussion started by: jiam912
8 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
Class::DBI::Plugin::RetrieveAll(3pm)			User Contributed Perl Documentation		      Class::DBI::Plugin::RetrieveAll(3pm)

NAME
Class::DBI::Plugin::RetrieveAll - more complex retrieve_all() for Class::DBI SYNOPSIS
use base 'Class::DBI'; use Class::DBI::Plugin::RetrieveAll; my @by_date = My::Class->retrieve_all_sorted_by("date"); # or __PACKAGE__->retrieve_all_sort_field('date'); my @by_date = My::Class->retrieve_all; DESCRIPTION
This is a simple plugin to a Class::DBI subclass that allows for simple sorting of the results of a retrieve_all(). There are two main ways to use this. Firstly, we create a new method 'retrieve_all_sorted_by' which takes an argument of how to sort. We also add a method for 'retrieve_all_sort_field' that sets a default field that any retrieve_all() will use for sorting. METHODS
retrieve_all_sorted_by my @by_date = My::Class->retrieve_all_sorted_by("date"); This method will be exported into the calling class, and allows for retrieving all the objects of the class, sorted by the given column. The argument given will be passed straight through to the database 'as is', and is not checked in any way, so an error here will usually in an error from the database, rather than Class::DBI itself. This makes it possible to pass more complex ORDER BY clauses through: my @by_date = My::Class->retrieve_all_sorted_by("date DESC, reference_no"); retrieve_all_sort_field __PACKAGE__->retrieve_all_sort_field('date'); This method changes the default retrieve_all() in the Class to be auto-sorted by the field given. Again this will be passed through directly, so you can have complex ORDER BY clauses. AUTHOR
Tony Bowden BUGS and QUERIES Please direct all correspondence regarding this module to: bug-Class-DBI-Plugin-RetrieveAll@rt.cpan.org COPYRIGHT and LICENSE Copyright (C) 2004-2006 Kasei. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.0 2006-01-16 Class::DBI::Plugin::RetrieveAll(3pm)
All times are GMT -4. The time now is 01:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy