Find the average based on similar names in the first column
I have a table, say this:
I want a code that will sort my data according to the first column and for ALL columns with the same name, calculate the average of each of the corresponding columns. In this case it would be:
If the 4th column has - sign then the names in 3rd column has to change to some user defined names (as shown in output).
Thanx
input1
1 a aaaaa +
2 b bbbbb +
3 c ccccc +
4 d ddddd +
5 e eeeee +
6 f xxxxx +
8 h hhhhh +... (8 Replies)
Hi Friends,
In continuation to my earlier post
https://www.unix.com/shell-programming-scripting/99166-script-find-average-given-column-also-specified-number-rows.html
I am extending my problem as follows.
Input:
Column1 Column2
MAS 1
MAS 4 ... (2 Replies)
Hi,
I'm new to shell programming, can anyone help me on this? I want to do following operations -
1. Average salary for each country
2. Total salary for each city
and data that looks like -
salary country city
10000 zzz BN
25000 zzz BN
30000 zzz BN
10000 yyy ZN
15000 yyy ZN
... (3 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
I am trying to complete a script which will allow me to find:
a) reads a value from the keyboard. (ask the... (4 Replies)
Hi i have data with two columns like below.
I want to find average of column values like if the value in column 2 is between 0-250000 the average of column 1 is some xx and average of column2 is ww then if value is 250001-5000000 average of column 1 is yy and average of column 2 is zz.
And my... (5 Replies)
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)
Hi,
My input file
Gene1 1
Gene1 2
Gene1 3
Gene1 0
Gene2 0
Gene2 0
Gene2 4
Gene2 8
Gene3 9
Gene3 9
Gene4 0
Condition:
If the first column matches, then look in the second column. If there is a value of zero in the second column, then don't consider that record while averaging.
... (5 Replies)
Discussion started by: jacobs.smith
5 Replies
LEARN ABOUT REDHAT
pdl::reduce
Reduce(3) User Contributed Perl Documentation Reduce(3)NAME
PDL::Reduce -- a "reduce" function for PDL
DESCRIPTION
Many languages have a "reduce" function used to reduce the rank of an N-D array by one. It works by applying a selected operation along a
specified dimension. This module implements such a function for PDL by providing a simplified interface to the existing projection func-
tions (e.g. "sumover", "maximum", "average", etc).
SYNOPSIS
use PDL::Reduce;
$a = sequence 5,5;
# reduce by adding all
# elements along 2nd dimension
$b = $a->reduce('add',1);
@ops = $a->canreduce; # return a list of all allowed operations
FUNCTIONS
reduce
reduce dimension of piddle by one by applying an operation along the specified dimension
$a = sequence 5,5;
# reduce by adding all
# elements along 2nd dimension
$b = $a->reduce('add',1);
$b = $a->reduce('plus',1);
$b = $a->reduce('+',1); # three ways to do the same thing
[ As an aside: if you are familiar with threading you will see that this is actually the same as
$b = $a->mv(1,0)->sumover
]
NOTE: You should quote the name of the operation (1st arg) that you want "reduce" to perform. This is important since some of the names are
identical to the names of the actual PDL functions which might be imported into your namespace. And you definitely want a string as argu-
ment, not a function invocation! For example, this will probably fail:
$b = $a->reduce(avg,1); # gives an error from invocation of 'avg'
Rather use
$b = $a->reduce('avg',1);
"reduce" provides a simple and unified interface to the projection functions and makes people coming from other data/array languages hope-
fully feel more at home.
$result = $pdl->reduce($operation [,$dim]);
"reduce" applies the named operation along the specified dimension reducing the input piddle dimension by one. If the dimension is omitted
the operation is applied along the first dimension. To get a list of valid operations see canreduce.
canreduce
return list of valid named "reduce" operations Some common operations can be accessed using a number of names, e.g. '+', "add" and "plus"
all sum the elements along the chosen dimension.
@ops = PDL->canreduce;
This list is useful if you want to make sure which operations can be used with "reduce".
AUTHOR
Copyright (C) 2000 Christian Soeller (c.soeller@auckland.ac.nz). All rights reserved. There is no warranty. You are allowed to redistribute
this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is sepa-
rated from the PDL distribution, the copyright notice should be included in the file.
perl v5.8.0 2001-07-07 Reduce(3)