Message-ID: <AS8P194MB099980A639EB635D298BF6DB9ACD9@AS8P194MB0999.EURP194.PROD.OUTLOOK.COM>
Date: 2021-09-01T20:59:42Z
From: Eliza Botto
Subject: conditional replacement of elements of matrix with another matrix column
deaR useRs,
I have the matrix "A" and matrix "B" and I want the matrix "C". Is there a way of doing it?
> dput(A)
structure(c(12, 12, 12, 13, 13, 13, 14, 14, 14, NA, NA, NA, NA,
NA, NA, NA, NA, NA), .Dim = c(9L, 2L))
> dput(B)
structure(c(11, 11, 11, 13, 13, 13, 14, 14, 14, 6, 7, 8, 9, 10,
11, 12, 13, 14), .Dim = c(9L, 2L))
> dput(C)
structure(c(12, 12, 12, 13, 13, 13, 14, 14, 14, NA, NA, NA, 9,
10, 11, 12, 13, 14), .Dim = c(9L, 2L))
Precisely, I want to replace the elements of 2nd column of A with those of B provided the elements of 1st column match. Is there a single line loop or code for that?
Thanks in advance,
Eliza Botto
[[alternative HTML version deleted]]