This is just a simplified example of what I am trying to accomplish:
I have nine objects (named A1-A9), each containing 3 random numbers. I want the mean of these three numbers for each object. That's easy enough for me to accomplish on my own:
lapply(1:9, function(y){
mean(A[y])
})
The catch is, I want that mean value to become the fourth value in each object. So, the fourth value in A1 is the mean of the first three values in A1, and etc. Again I could do that, but all I can think of is to just run the mean() function nine times for each object. Is it possible to loop through those existing variable names within a lapply (or any) loop in R? So, something to this effect, but that actually works:
lapply(1:8, function(y){
A[y][4] <- mean(A[y])
})
Where the unique part of the object name is looped (y), and the result of the function is assigned to it in the fourth spot.