<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Schadenfreude &#187; statistics</title>
	<atom:link href="http://www.ralree.com/tag/statistics/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ralree.com</link>
	<description>Malicious enjoyment derived from observing someone else's misfortune</description>
	<lastBuildDate>Thu, 09 Feb 2012 01:49:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Calculating Averages from a CSV with Perl</title>
		<link>http://www.ralree.com/2007/12/08/calculating-averages-from-a-csv-with-perl/</link>
		<comments>http://www.ralree.com/2007/12/08/calculating-averages-from-a-csv-with-perl/#comments</comments>
		<pubDate>Sat, 08 Dec 2007 18:09:00 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[crime]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://www.ralree.info/2007/12/13/calculating-averages-from-a-csv-with-perl</guid>
		<description><![CDATA[Code Here&#8217;s a quick one-liner using some UNIX utilities and Perl to construct some nice averages from CSV data: for i in `seq 2 20`; do cat crim_rate_2005_by_state.csv &#124; cut -d , -f $i &#124; perl -e '$c=$d=0;$e;while(&#60;&#62;){if(/^\d/){$c+=$_;$d+=1}else{s/\s{2,}/ /g;s/"//g;chomp($e=$_);}} print $e, ": ", $c/$d, "\n"'; done And now, the spaced out version: #!/bin/bash for i in `seq 2 20`; do cat crim_rate_2005_by_state.csv &#124; \ cut -d , -f $i &#124; \ perl -e '$c=$d=0; $e; while(&#60;&#62;){ if(/^\d/){ $c+=$_; $d+=1 } [...]]]></description>
			<content:encoded><![CDATA[<h2>Code</h2>
<p>Here&#8217;s a quick one-liner using some UNIX utilities and Perl to construct some nice averages from CSV data:</p>
<pre><code>
for i in `seq 2 20`; do cat crim_rate_2005_by_state.csv | cut -d , -f $i | perl -e '$c=$d=0;$e;while(&lt;&gt;){if(/^\d/){$c+=$_;$d+=1}else{s/\s{2,}/ /g;s/"//g;chomp($e=$_);}} print $e, ": ", $c/$d, "\n"'; done
</code></pre>
<p>And now, the spaced out version:</p>
<pre><code>
#!/bin/bash
for i in `seq 2 20`; do
  cat crim_rate_2005_by_state.csv | \
  cut -d , -f $i | \
  perl -e '$c=$d=0;
    $e;
    while(&lt;&gt;){
      if(/^\d/){
        $c+=$_;
        $d+=1
      } else {
        s/\s{2,}/ /g;
        s/"//g;
        chomp($e=$_);
      }
    }
    print $e, ": ", $c/$d, "\n"';
done
</code></pre>
<h2>Output</h2>
<ul>
<li>Population: 5775431.88461538</li>
<li>Violent crime rate: 418.930769230769</li>
<li>Murder/manslaughter rate: 5.59038461538462</li>
<li>Forcible rape rate: 33.1634615384615</li>
<li>Robbery rate: 114.455769230769</li>
<li>Assault rate: 265.728846153846</li>
<li>Property crime rate: 3339.50961538462</li>
<li>Burglary rate: 685.671153846154</li>
<li>Larceny/theft rate: 2273.43269230769</li>
<li>Motor vehicle theft rate: 380.417307692308</li>
<li>Violent crime: 26928.3461538462</li>
<li>Murder and nonnegligent manslaughter: 335.730769230769</li>
<li>Forcible rape: 1809.67307692308</li>
<li>Robbery: 8128.30769230769</li>
<li>Aggravated assault: 16654.6346153846</li>
<li>Property crime: 196569.711538462</li>
<li>Burglary: 41756.0961538462</li>
<li>Larceny-theft: 130880.442307692</li>
<li>Motor vehicle theft: 23933.1730769231</li>
</ul>
<p>So, now we have our averages.  More work to be done.  The data file used is available here:</p>
<h3><a href="http://ralree.com/assets/2007/12/8/crim_rate_2005_by_state.csv">crim_rate_2005_by_state.csv</a></h3>
]]></content:encoded>
			<wfw:commentRss>http://www.ralree.com/2007/12/08/calculating-averages-from-a-csv-with-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

