[R] applying cbind (or any function) across all components in a list

Hans Thompson hans.thompson1 at gmail.com
Thu May 24 18:49:13 CEST 2012


I'm confused why I haven't made clear what I am asking for help with.  

I have two different lists with two (or many) components, [[1]] and [[2]]. 
One of the list has components with dim=c(2,3) and the other has dim=c(2,2). 
I want to create a new list with components dim=c(2,4) by binding together
the averages of the columns using 

> cbind((l1[[1]][,1]+l2[[1]][,1])/2, (l1[[1]][,2]+l2[[1]][,1])/2,
> (l1[[1]][,2]+l2[[1]][,2])/2, (l1[[1]][,3]+l2[[1]][,2])/2)

which should put out:

     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]    2    3    4    5

my problem is finding out how I can apply this function to all the
components within the list in the same function.

--
View this message in context: http://r.789695.n4.nabble.com/applying-cbind-or-any-function-across-all-components-in-a-list-tp4631128p4631228.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list