How to create this function for lapply? I have two lists of dataframes. List x and list my_list. Each having four dataframes and their names are same for the two lists, i.e., bray-curtis, Chao1, FB, and Shannon.
The dataframes within the two lists have same element names, but they contain different information. This is because list x has been generated after some operations on list my_list.
Now I want to write a function and run that on list x with `lapply. the command I want to write as a function is
forest(x$Chao1, slab = paste(my_list$Chao1$StudyID))

Here, the first Chao1 is coming from list x while the second  Chao1 is coming from the list my_list. It works for a single dataframe but I am unable to write the codes with lapply so that it runs across all the dataframes of the lists.
The desired outputs are four plots from four dataframes of list x.
Can anyone please help me?
Update: @gringer's approach works, but it saves all the plots in a single list. When I tried to save the images with following command it just saved the last image:
tiff(filename = &quot;~/Desktop/image.tiff&quot;, width = 30, height = 30, units = &quot;cm&quot;, res = 1200)

Is there a way to save all them individually?
Thanks
Assuming the lists are named, and you want to fetch the element with the same name from each list, I'm guessing something like this would work (or at least get you closer to a solution):
v &lt;- lapply(names(x), function(var){
   forest(x[[var]], slab=(my_list[[var]])$StudyID)
})

When creating images that don't have a multi-page format (i.e. anything except PDF), and not changing the image name with each save, you need to add in a format specifier to tell R what to do with new created images. For example, this will add a three digit zero-padded number for each new TIFF image:
tiff(filename = &quot;~/Desktop/image_%03d.tiff&quot;, width = 30, height = 30, units = &quot;cm&quot;, res = 1200)