The problem is that your function is returning x$Y rather than x so
the result is a list of Y's rather than a list of the x's with Y added.
You want function(x) { x$Y <- x$A * x$B; x } or a bit shorter:
lapply(mylist, transform, Y = A * B)
On Jan 18, 2008 10:37 AM, Chuck Cleland <[EMAIL PROTE
What is the right way to assign a new variable into each a of list of
data frames? Here is my failed attempt:
mylist <- list(df1 = data.frame(A = runif(5), B = runif(5)),
df2 = data.frame(A = runif(5), B= runif(5)))
lapply(mylist, function(x){x$Y <- x$A * x$B})
$df1
[1] 0.25
2 matches
Mail list logo