Re: [R] Assigning into each of a list of dataframes

2008-01-18 Thread Gabor Grothendieck
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

[R] Assigning into each of a list of dataframes

2008-01-18 Thread Chuck Cleland
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