Skip to content
Back to formatted view

Raw Message

Message-ID: <1337878153389-4631228.post@n4.nabble.com>
Date: 2012-05-24T16:49:13Z
From: Hans Thompson
Subject: applying cbind (or any function) across all components in a list
In-Reply-To: <CAFEqCdxgzPAn9RD5xw73LdsEz026dpszfw3GnkB4a5SqaKprHQ@mail.gmail.com>

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.