Like this:
stats <- lapply(stats, transform, totalGFP = AVGFP * Area)
I'll do my best to explain but please refer to ?lapply
and ?transform
for the full docs.
transform
is a function to add columns to a data.frame, according to formulas of the type totalGFP = AVGFP * Area
passed as arguments. For example, to add the totalGFP
column to your first data.frame, you could run transform(stats[[1]], totalGFP = AVGFP * Area)
.
lapply
applies a function (here transform
) to each element of a list or a vector (here stats
), and returns a list. If the function to be applied requires more arguments, they can be passed at the end of the lapply
call, here totalGFP = AVGFP * Area
. So here lapply
is an elegant way of running transform
on each element of stats
.