Hello,
I would like to use the cbind() function to construct a matrix used in the
middle of a function as following
for (i in 1:1000) {
b[i] <- function(cbind(a[[1]][[i]],
a[[2]][[i]],a[[3]][[i]],...a[[67]][[i]]))
}
Is there an easy way of achieving this rather than "cbind" every
column?
--
View this message in context:
http://www.nabble.com/cbind%28%29-tf4724534.html#a13507633
Sent from the R help mailing list archive at Nabble.com.
Hi
Perhaps:
Hi,
Try this:
do.call("rbind", lapply(a, function(x)do.call("cbind", x)))
On 31/10/2007, livia <yn19832@msn.com> wrote:>
>
> Hello,
>
> I would like to use the cbind() function to construct a matrix used in the
> middle of a function as following
>
> for (i in 1:1000) {
> b[i] <- function(cbind(a[[1]][[i]],
> a[[2]][[i]],a[[3]][[i]],...a[[67]][[i]]))
> }
>
>
> Is there an easy way of achieving this rather than "cbind" every
column?
> --
> View this message in context:
> http://www.nabble.com/cbind%28%29-tf4724534.html#a13507633
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]
On 10/31/2007 8:06 AM, livia wrote:> Hello, > > I would like to use the cbind() function to construct a matrix used in the > middle of a function as following > > for (i in 1:1000) { > b[i] <- function(cbind(a[[1]][[i]], > a[[2]][[i]],a[[3]][[i]],...a[[67]][[i]])) > } > > > Is there an easy way of achieving this rather than "cbind" every column?What you're doing is a little complicated (taking the i'th element out of elements 1:67 in a list), so the solution is bound to be a little complicated too. But something like this will save you typing: # construct a list of the i'th elements ithelements <- lapply(a[1:67], function(e) e[[i]]) # pass them as args to cbind do.call(cbind, ithelements) I haven't tested this (not having your data at hand), but if it doesn't work, something like it should. Duncan Murdoch