Maybe define a function with two arguments? e.g. oo <- function(dataset, i) {...}
I replaced lapply with map because I found that lapply didn't take the 1:length(mtcars) vector. Essentially, both functions are alternative forms of a simple for-loop. There is a names function for getting the names of all variables in the dataframe mtcars, but, unfortunately, it only works for the dataframe object but not each variable in the dataframe. Good luck!