Q: Recoding over multiple data frames in R (edited to reflect help...I'm not doing great with formatting, but appreciate the feedback)
I'm a bit stuck on what I suspect is an easy enough problem. I have multiple different data sets that I have loaded into R, all of which have different numbers of observations, but all of which have two variables named "A1," "A2," and "A3".  I want to create a new variable in each of the three data frames that contains the value held in "A1" if A3 contains a value greater than zero, and the value held in "A2" if A3 contains a value less than zero. Seems simple enough, right?
My attempt at this code uses this faux-data:
set.seed(1)
A1=seq(1,100,length=100)
A2=seq(-100,-1,length=100)
A3=runif(100,-1,1)
df1=cbind(A1,A2,A3)

A3=runif(100,-1,1)
df2=cbind(A1,A2,A3)

I'm about a thousand percent sure that R has some functionality for creating the same named variable in multiple data frames, but I have tried doing this with lapply:
mylist=list(df1,df2)
lapply(mylist,function(x){
  x$newVar=x$A1
  x$newVar[x$A3>0]=x$A2[x$A3>0]
  return(x)
})

But the newVar is not available for me once I leave the lapply loop. For example, if I ask for the mean of the new variable:
    mean(df1$newVar)
    [1] NA
    Warning message:
    In mean.default(df1$newVar) :
    argument is not numeric or logical: returning NA
Any help would be appreciated.
Thank you.

A: Well first of all, df1 and df2 are not data.frames but matrices (the dollar syntax doesn't work on matrices).
In fact, if you do:
set.seed(1)
A1=seq(1,100,length=100)
A2=seq(-100,-1,length=100)
A3=runif(100,-1,1)
df1=as.data.frame(cbind(A1,A2,A3))

A3=runif(100,-1,1)
df2=as.data.frame(cbind(A1,A2,A3))

mylist=list(df1,df2)
lapply(mylist,function(x){
  x$newVar=x$A1
  x$newVar[x$A3>0]=x$A2
})

the code almost works but gives some warnings. In fact, there's still an error in the last line of the function called by lapply. If you change it like this, it works as expected: 
lapply(mylist,function(x){
  x$newVar=x$A1
  x$newVar[x$A3>0]=x$A2[x$A3>0] # you need to subset x$A2 otherwise it's too long
  return(x) # better to state explicitly what's the return value
})


EDIT (as per comment):
as basically always happens in R, functions do not mutate existing objects but return brand new objects.
So, in this case df1 and df2 are still the same but lapply returns a list with the expected 2 new data.frames i.e. :
resultList <- lapply(mylist,function(x){
  x$newVar=x$A1
  x$newVar[x$A3>0]=x$A2[x$A3>0]
  return(x)
})

newDf1 <- resultList[[1]]
newDf2 <- resultList[[2]]

