Why not simply
a-1:3
b-4:5
c(a,b)
[1] 1 2 3 4 5
2014-03-22 23:22 GMT+01:00 Tham Tran hanhtham.t...@yahoo.com.vn:
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
Thanks for your help
Tham
--
View this
He wants a[1] b[1] a[2] b[2] a[3] b[3]
I think you can do:
x = as.vector(rbind(a, b))
On Mon, Mar 24, 2014 at 2:39 PM, Frans Marcelissen
fransiepansiekever...@gmail.com wrote:
Why not simply
a-1:3
b-4:5
c(a,b)
[1] 1 2 3 4 5
2014-03-22 23:22 GMT+01:00 Tham Tran
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
Thanks for your help
Searching Stackoverflow for [r] interleave produced this idea fron @Arun, which
I think is
Just to satisfy my curiosity:
library(microbenchmark)
a - 1:10
b - 101:110
microbenchmark(
+ m1=as.vector( rbind(a,b) ),
+ m2=c( rbind(a,b) ),
+ m3=as.vector( matrix(c(a,b), nrow=2, byrow=TRUE) ),
+ m4={x - integer(length(a)*2); x[c(TRUE,FALSE)] - a;
x[c(FALSE,TRUE)] - b; x},
+ m5={x -
Many thank for all your answers. it has helped me save time
--
View this message in context:
http://r.789695.n4.nabble.com/Merge-two-vectors-into-one-tp4687361p4687447.html
Sent from the R help mailing list archive at Nabble.com.
__
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) )
Leaving in the usual footer because Nabble's interface usually omits
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
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
Thanks for your help
Tham
--
View this message in context:
http://r.789695.n4.nabble.com/Merge-two-vectors-into-one-tp4687361.html
Sent from the R help mailing list archive
Hi,
May be this helps:
a - 1:3
b - 4:6
z - as.vector(rbind(a,b))
z
#[1] 1 4 2 5 3 6
#or
z1 - setNames(c(a,b),rep(seq_along(a),2))
z1 - as.vector(z1[order(names(z1))])
z1
#[1] 1 4 2 5 3 6
A.K.
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
Hi all,
I have two vectors like this:
x - c( Y, H, NA, NA )
y - c( NA, H, NA, B )
And would like to make one vector with the common elements, and the element
available only in one of the vectors.
res - c( Y, H, NA, B )
Thanks,
Patricia
From:
Hi,
Sorry, the answers are yes yes yes. And thank you for your idea it works
perfectly.
Regards
Patricia
Date: Wed, 28 Jan 2009 16:01:11 +0100
Subject: Re: [R] Merge two vectors into one.
From: csa...@rmki.kfki.hu
To: kurtney...@hotmail.com
CC: r-help@r-project.org
Is position important? The vectors always have the same length? They
always have the same entry if both are not NA?
If yes, yes and yes, then
res - ifelse( is.na(x), y, x)
does what you want. Otherwise please explain better what you want.
Gabor
On Wed, Jan 28, 2009 at 3:54 PM, patricia garcía
you could start by something like the following:
x - c(Y, H, NA, NA)
y - c(NA, H, NA, B)
ifelse(is.na(x), y, x)
I hope it helps.
Best,
Dimitris
patricia garcía gonzález wrote:
Hi all,
I have two vectors like this:
x - c( Y, H, NA, NA )
y - c( NA, H, NA, B )
And would
13 matches
Mail list logo