Using lapply with data.table to generate several outputs at once.

I changed the code in blockquotes to formatted code blocks (using the </> button), which is how code is supposed to be presented. This will make it more likely that somebody will respond to your query..