Merge two vectors based on index in R -


I am trying to merge two vectors of the same length where the vector in NX "a" Align with "b" and vice versa:

  a < - c (1, na, 3, na) b & lt; - c (NA, 2, NA, 4)   

should be output:

  1, 2, 3, 4   

Thanks for the help!

Edit: The solution I used was

  a is.na (a)]  [b] is [an isna]    

value a is.na ( A) should be replaced with the value of b , which corresponds to the denial of is.na (b) . Here I define a new vector d so that the original vector should be written on a or b .
  D & LT; - Ad [is.na (d)] & lt; - b [! Is.na (B)] d # [1] 1 2 3 4   

If you find that the value of NA starts in the second position, you assign Can also be optional.

  d & lt; - Ad [c (wrong, right)]    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -