Create a function with many parameters and apply it over a list in R