# Re: [ferret_users] addition in ferret

Thanks Ansley, It worked.

--
Regards,
Nitin Patil

On Wed, Aug 20, 2014 at 10:33 PM, Ansley Manke wrote:
Ninin,
So, to take the average you'll need to divide by the count of valid data in the two rows at each position.
```   gp1    gp2    sum

0.681  0.716  1.398
0.664  0.911  1.575
1.101  0.724  1.825
1.125  0.844  1.968
0.516  0.713  1.228
0.463  0.388  0.851
0.801   ....   ....
0.651  0.899  1.550
0.715  0.795  1.510
0.656  0.580  1.237```

! 1 if the data is valid, 0 otherwise.  (see below for a note about IF vs IFV.)

yes? let gp1_good = ifv gp1 then 1 else 0
yes? let gp2_good = ifv gp2 then 1 else 0

yes? list gp1_good, gp2_good
...
1    /  1:   1.000   1.000
2    /  2:   1.000   1.000
3    /  3:   1.000   1.000
4    /  4:   1.000   1.000
5    /  5:   1.000   1.000
6    /  6:   1.000   1.000
7    /  7:   1.000   0.000
8    /  8:   1.000   1.000
9    /  9:   1.000   1.000
10   / 10:   1.000   1.000
...

yes? let count = gp1_good + gp2_good

and you could divide the variable sum by count for the average.

Notice I used IFV in the definitions for gp1_good and gp2_good.  This is a special version of IF, which is TRUE if the data is valid, even when the value itself is zero. Using just the IF command would return FALSE for valid values of exactly zero.

yes? list IF {2., 0., 3} then 1
VARIABLE : IF {2., 0., 3} THEN 1
SUBSET   : 3 points (X)
1   / 1:  1.000
2   / 2:   ....
3   / 3:  1.000

yes? list  IFV {2., 0., 3} then 1
VARIABLE : IFV {2., 0., 3} THEN 1
SUBSET   : 3 points (X)
1   / 1:  1.000
2   / 2:  1.000
3   / 3:  1.000

On 8/20/2014 3:46 AM, Nitin Patil wrote:
Thanks Ansley for the solution. Sorry I forgot to ask in my previous email.

If I have to take the mean for the two columns (as per in my previous email attached txt file) instead of sum, I can,t do straight forward due to missing. What I tried is:

let sum = MISSING(gp1, 0) + MISSING(gp2, 0)
let mean=sum/2

bz It will give wrong mean for missing row. Any solution to this.

--
Regards,
Nitin Patil

On Tue, Aug 19, 2014 at 11:14 PM, Ansley Manke wrote:
Hi Nitin,
In Ferret, missing + variable = missing.  (This is true for all operations, and it's probably more intuitive if you think, what should be the result if you were multiplying or dividing the variables? Missing*2 = ?)

If you want to have the sum contain any values that do exist then you'll need to fill in any missing data with zero's.  Either define new variables with an IF statement like
let gp1var = if gp1  then gp1 else 0
let gp2var = if gp2  then gp2 else 0
and add those, or you could use the MISSING function to substitute 0 where either variable is missing.
let sum = MISSING(gp1, 0) + MISSING(gp2, 0)

Ansley

On 8/19/2014 1:33 AM, Nitin Patil wrote:
Dear ferret users,

I am adding simply 2 defined variables in my script (attached) but it is not doing addition, any idea (output is also attached).

It is not accepting "...." in output file in one of the column for addition.
--
Regards,
Nitin Patil