[R] add a special column to a matrix

Lida Zeighami lid.zigh at gmail.com
Tue Jul 7 16:42:56 CEST 2015


Hi there,

I have a two matrices which they have a common column! I want to add the a
column of second to matrix to the equivalent column of first matrix!
my first matrix is
head(mat1)
a       b         c           d
fg    1:23       dfgv       5
pt    10:18     tgtgh      1
wq   15:123    oiljk       6
fg     9:1323    ass       4
yr     12:123    kjjlk       5

my second matrix:
head(mat2)
       e            q
  1:23             0
   10:18           1
  14:455          2
   15:123         2
    9:1323        2
    12:123        1
     5:1548        0

mat1 and mat2 have a common column (b and e) but is not in the same order,
I want to add the q column from mat2 to be added to mat1
my output will be:

head(mat)
a       b         c           d         q
fg    1:23       dfgv       5        0
pt    10:18     tgtgh      1        1
wq   15:123    oiljk       6        2
fg     9:1323    ass       4        2
yr     12:123    kjjlk       5        1

would you please let me know how to do it?

Thanks

	[[alternative HTML version deleted]]



More information about the R-help mailing list