useful r functions; leaning towards functional programming