My program is passed a list mylist
of several dataframes with arbitrary names:
FOO 12 tbl_df list
BAR 12 tbl_df list
...
Each dataframe has the same structure:
variableX variableY SUBJECT_ID SUBJECT_YEAR SUBJECT_TOWN
2 1 A 1950 Townsville
1 2 B 1951 Villestown
...
I need to iterate over mylist
, getting for each dataframe one plot of the mean of variableX
per SUBJECT_YEAR
and SUBJECT_TOWN
to be exported as a uniquely named image file (e.g. FOO_SUBJECTOWN.png
).
I know that R can handle this kind of task very well and there are good examples on SO of this task performed with a for-loop. However, because I am new to functions in R, I would like to know how this task could be performed efficiently using a function.