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

Hans Thompson hans.thompson1 at gmail.com
Wed May 23 21:58:19 CEST 2012


#If I have two lists as follows

a1<-  array(1:6, dim=c(2,3))
a2<-  array(7:12, dim=c(2,3))
l1<-  list(a1,a2)



a3<-  array(1:4, dim=c(2,2))
a4<-  array(5:8, dim=c(2,2))
l2<-  list(a3,a4)


#how can I create a new list with the mean across all arrays within the
list, so all components are included?  As an example for [[1]];

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)



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



More information about the R-help mailing list