Thanks for the codes. Maybe I elaborate more here.

In my actual dataset, the dim(E) = (200, 20, 1000)  and dim(C) = (200,15,
965) in which I don't know which 35 matrix are missing. I want to ask how
merge the two arrays by matching the first 5 columns of values. Thanks you.

Best Regards,
Ray

On Thu, Feb 7, 2013 at 10:29 PM, arun <smartpink...@yahoo.com> wrote:

> Hi,
>
> I didn't fully understand the logic.
> You could get the result by:
>  list1<-lapply(mapply(cbind,lapply(1:2,function(i)
> E[,,i]),lapply(c(1,3),function(i) C[,i,]),SIMPLIFY=FALSE),function(x)
> x[,c(TRUE,apply(matrix(!x[,-1]%in% x[,1],nrow=5),2,all))])
> Fnew<-array(unlist(list1),dim=c(dim(list1[[1]]),length(list1)))
>
>  identical(F,Fnew)
> #[1] TRUE
> A.K.
>
>
> ----- Original Message -----
> From: Ray Cheung <ray1...@gmail.com>
> To: r-help@r-project.org
> Cc:
> Sent: Wednesday, February 6, 2013 10:16 PM
> Subject: [R] Merging data in arrays
>
> Dear All,
>
> Here is a hypothetical sample (sorry for the clumsy code):
>
> A1 <- matrix(1:5, nrow=5, ncol=1)
> A2 <- matrix(6:10, nrow=5, ncol=1)
> A3 <- matrix(11:15, nrow=5, ncol=1)
> A4 <- matrix(16:20, nrow=5, ncol=1)
> A5 <- matrix(21:25, nrow=5, ncol=1)
> A6 <- matrix(26:30, nrow=5, ncol=1)
>
> B1 <- matrix(c(A1, A2, A3), nrow=5, ncol=3)
> B2 <- matrix(c(A2, A3, A4), nrow=5, ncol=3)
> B3 <- matrix(c(A3, A4, A5), nrow=5, ncol=3)
>
> C <- array(c(B1, B2, B3), dim = c(5,3,3))
>
> D1 <- matrix(c(A1, A4, A5), nrow=5, ncol=3)
> D2 <- matrix(c(A3, A5, A6), nrow=5, ncol=3)
>
> E <- array(c(D1, D2), dim = c(5,3,2))
>
> In the above example, I want to merge array C to array E by matching the
> column 1. That is, the resultant array F should look like this:
>
> F1 <- matrix(c(A1, A4, A5, A2, A3), nrow=5, ncol=5)
> F2 <- matrix(c(A3, A5, A6, A4, A5), nrow=5, ncol=5)
> F <- array(c(F1, F2), dim = c(5,5,2))
>
> Would you please advise on the codes? Thank you very much for any help.
>
> Best Regards,
> Ray
>
>     [[alternative HTML version deleted]]
>
> ______________________________________________
> 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]]

______________________________________________
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.

Reply via email to