[R] Merge two vectors into one
Rolf Turner
r.turner at auckland.ac.nz
Mon Mar 24 01:07:41 CET 2014
On 24/03/14 08:37, David Winsemius wrote:
>
> On Mar 22, 2014, at 3:22 PM, Tham Tran wrote:
>
>> Dear R users,
>>
>> Given two vectors x and y
>> a=1 2 3
>> b=4 5 6
>>
>> i want to combine them into a single vector z as 1 4 2 5 3 6
>
> One way:
>
> c( matrix(c(a,b), nrow=2, byrow=TRUE) )
It is more perspicuous to use
as.vector(matrix(c(a,b), nrow=2, byrow=TRUE))
The end result is the same, but it is better to be explicit, rather than
relying on the side-effect of the c()-function.
See fortune("convert a matrix").
cheers,
Rolf
More information about the R-help
mailing list