I have 30 + csvs loaded and I would like to write a loop to go through each one and add the new column using my function but don't know howto. I guess I need to create a list from the dataframes first, then loop through this overwriting the orignal objects to create the new dfs with the extra column
you can make lists of files with dir() and list.files() functions <- if its csv's you want
otherwise the ls() function looks at named objects in your environment ('loaded csv's i.e. dataframes)
you can iterate nicely with map or walk functions from purrr package, which is part of the tidyverse.
dir() would be for your csv's rather than your data.frames... so it would be better to call it list_of_csvs or change to ls funtion and filter the result based on the class containing data.frame.
I note that the syntax for the for loop isnt right, as its missing round brackets like
for (i in list_of_dfs){
but I would also recommend purrr functions over for loops, something to think about
further note, all the functions such as dir() or ls() whether they are listing files on your drive, or frames in your r environment only list the names of the objects (as character vectors), so if you want to treat them as symbols , or get() the contents you would need an extra step