title: Calculate Average using PIG
body: <p>I am new to PIG and want to calculate Average of my one column data that looks like</p>
  
  <p>0<br>
  10.1<br>
  20.1<br>
  30<br>
  40<br>
  50<br>
  60<br>
  70<br>
  80.1<br></p>
  
  <p>I wrote this pig script</p>
  
  <pre><code>dividends = load 'myfile.txt' as (A);
  dump dividends
  grouped   = group dividends by A;
  avg       = foreach grouped generate AVG(grouped.A);
  dump avg
  </code></pre>
  
  <p>It parses data as</p>
  
  <p>(0)<br>
  (10.1)<br>
  (20.1)<br>
  (30)<br>
  (40)<br>
  (50)<br>
  (60)<br>
  (70)<br>
  (80.1)<br></p>
  
  <p>but gives this error for average</p>
  
  <pre><code>2013-03-04 15:10:58,289 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: Pig script failed to parse: 
  &lt;file try.pig, line 4, column 41&gt; Invalid scalar projection: grouped
  Details at logfile: /Users/PreetiGupta/Documents/CMPS290S/project/pig_1362438645642.log
  </code></pre>
  
  <p>ANY IDEA</p>