r - Union two Arrays by colnames -


i have 2 named arrays of different length:

x = setnames(c(0.3,0.5,0.1,0.2),c(4,5,7,9)) y = setnames(c(0,0,0,0,0,0,0,0,0),c(2,3,4,5,6,7,8,9,10)) 

and want union (or better: add) them column names, resulting in:

  2    3    4    5    6    7    8    9    10 0.0  0.0  0.3  0.5  0.0  0.1  0.0  0.2   0.0 

perhaps should mention 1 of arrays of class table, far understand it, nothing different named array.

you can subset element indicating names rather indices. works example:

  y[names(x)]<-x   #  2   3   4   5   6   7   8   9  10    #0.0 0.0 0.3 0.5 0.0 0.1 0.0 0.2 0.0  

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -