Vectorize examples

Sprinkled some vectorized programming in the examples to get some interesting speedups and a more idiomatic R style with fewer loops.