Your code is syntactically correct but goes against all R style guides I know.
I've changed that - but obviously you don't have to.
x1 <- c(a1 = 0, b3 = 2, e2 = -2)
x2 <- c(c = 3, d = 4, f = 5)
N <- c("a1", "b3", "d", "e2", "c", "f")
x3 <- c(x1, x2) # concatenate
x3 <- x3[N
Hello,
Lets say I have 2 vectors:
x1=c("a1"=0,"b3"=2,"e2"=-2);
x2=c("c"=3,"d"=4,"f"=5);
and vector of names in specific order:
N=c("a1","b3","d","e2","c","f")
and I want to combine them to vector C:
C=
a1 b3 d e2 c f
0 2 4 -2 3 5
Basically, just fill vector N with values from vector x1
2 matches
Mail list logo