Is this what you want:
> (a<-1:6)
[1] 1 2 3 4 5 6
> (b<-c(5,2))
[1] 5 2
> (m1<-match(a,b))
[1] NA 2 NA NA 1 NA
> cbind(a, b[m1])
a
[1,] 1 NA
[2,] 2 2
[3,] 3 NA
[4,] 4 NA
[5,] 5 5
[6,] 6 NA
>
Your 'missing function b' in the first example was due to you thinking
'b(m1[i])' is equivalent t
Dear list,
I have a long list of two vectors with some matching elements. I would like to
line them up in two columns and have an NA in those positions of the second
vector where a match is absent. With a simple example, I will explain my
problem.
(a<-1:6)
(b<-c(5,2))
(m1<-match(a,b))
(ab<-cbind
2 matches
Mail list logo