write a function that can take a parameter of one of your file names, read it, do your calculation, and write it out.
then use commands like list.files() to make a vector of file names you want to apply your function to.
then use purrr library to iterate your function over every file name that you want. (purrr::walk function)