title: Creating Histogram with Binning Averages
body: <p>I am making two histograms by using moving averages and binning. I have gotten a moving average of 18k data points , most that are 0 values ,by using excel.</p>
  
  <p>This is what I was looking to get done through R</p>
  
  <p><a href="http://postimg.org/image/rweahsps5/" rel="nofollow">"Moving Average"</a> </p>
  
  <p>I would like to use R in order to make a script that will produce a histogram of how many ‘counts’ a device received.  I have tried : </p>
  
  <pre><code>hist(y, 20)  
  hist (y, ) 
  plot (y, x) 
  </code></pre>
  
  <p>and now , after three days of learning this is what I got : </p>
  
  <pre><code>y &lt;- AltWithAllCounts$Cts.p.ms
  x &lt;- AltWithAllCounts$Alt 
  barwidth &lt;- 100 
  #how many bins
  block &lt;- rep(seq(1,length(x)/barwidth),each=barwidth)
  #makes bins
  a &lt;- aggregate(y,by=list(block),sum) 
  #creates sum of bins
  altmean &lt;- aggregate(x,by=list(block),mean)
  #finds mean altitude of each bin
  avgCount &lt;- a$x/barwidth
  #averages out each bin
  plot(altmean$x,avgCount,xlab="Altitude",ylab="Counts") 
  # creates scatterplot of mean bins
   avgBinCnt &lt;- data.frame(altmean$x,a$x)
  write.csv(avgBinCnt,file="avgBinCnt.csv",)
  </code></pre>
  
  <p>The idea is that I want to the average sum of 20 values and plot it over time  , which is x  </p>
  
  <pre><code>x       y
  851304  0
  851404  0
  851503  0
  851603  1
  851703  0
  851804  0
  851904  0
  852107  0
  852203  0
  852303  0
  922503  0
  922603  2
  922703  0
  922804  0
  922904  0
  923107  0
  923203  0
  923303  0
  923404  0
  923504  0
  923604  0
  923703  0
  923803  0
  923904  0
  924108  0
  924205  1
  1441603 0
  1441703 0
  1441804 0
  1441904 0
  1442107 1
  1442203 1
  1442304 0
  1442404 4
  1442504 0
  1442605 1
  1442703 6
  1442803 8
  1442904 0 
  </code></pre>