Skip to content

Instantly share code, notes, and snippets.

@andrewvc
Created September 30, 2012 17:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewvc/3807772 to your computer and use it in GitHub Desktop.
Save andrewvc/3807772 to your computer and use it in GitHub Desktop.
Thinking Stats first exercise, using shell instead of python
#!/bin/sh
split_cmd='cut -b 275,276,277,278,279 2002FemPreg.dat'
first_avg=`$split_cmd | grep '1 1$' | cut -b 1,2 | awk '{s += $1} END { print s/NR }'`
other_avg=`$split_cmd | grep -v ' 1$' | grep '1..$' | cut -b 1,2 | awk '{s += $1} END { print s/NR }'`
hours_diff=`echo "($first_avg-$other_avg)*168" | bc`
echo First borns: $first_avg weeks
echo Non-first borns: $other_avg weeks
echo Difference: $hours_diff hours
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment