I have a list of dataframes. I want to perform an operation on columns of the dataframes and then create a new column in the dataframes with the resulting new column.
a <- data.frame(c(1,2,3), c(2,3,4))
b <- data.frame(c(7,8,9), c(5,6,2))
l <- list(a, b)
lapply(l, function(x) x[,2]*2)
What I want is for 4 6 8
and 10 12 4
to be assigned to the third columns of the first and second dataframes, respectively.
This does not seem to work:
lapply(l, function(x) x[,2]*2 -> x$new)