lapply will do the trick, try something like
lapply(1:length(dat1), function(x,dat1,dat2) cbind(dat1[[x]][,1:2],
dat2[[x]]),dat1,dat2)

HTH
Schalk

On Mon, Mar 22, 2010 at 10:18 AM, Ron_M <ron_michael70@yahoo.com> wrote:

>
> Dear all,
>
> I have following two list object, both are basically collection of matrices
> :
>
> dat1 <- matrix(rnorm(25*6), ncol=6)
> dat1 <- split(dat1, seq(5,25,by=5))
> dat1 <- lapply(dat1, matrix, ncol=6)
>
> dat2 <- matrix(rnorm(25*4), ncol=4)
> dat2 <- split(dat2, seq(5,25,by=5))
> dat2 <- lapply(dat2, matrix, ncol=4)
>
>
> Now I want to replace last 4 columns of each matrix at "dat1" with the
> corresponding matrix in "dat2". However I want to avoid the time consuming
> loop to do that. Is there any way to do that without using loop?
>
> Thanks
> --
> View this message in context:
> http://n4.nabble.com/Replacing-elements-of-list-tp1677293p1677293.html
> 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.
>

	[[alternative HTML version deleted]]

