I am trying to avoid a whole lot of repeating myself (copy/pasting) by using functions in my R code. I have a working function as per below, but I can\'t figure out how to build