R functions for repetitive tasks