A function in R to easily apply functions to dataset