# Re: [R] Simple... but...

From: Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk_at_idi.ntnu.no>
Date: Wed, 23 Jul 2008 16:06:27 +0200

it's clear, he wants to combine x and y s that the result is (x[1], y[1], x[2], y[2], ...), unless i am confused as well ;)

now, both rbind(x,y)[1:length(x)] and as.vector(mapply(c,x,y)) do the job, but the former is *much* faster:

t1 = function(n) as.vector(mapply(c, 1:n, 1:n)) t2 = function(n) rbind(1:n,1:n)[1:(2*n)]

system.time(t1(10^6)) # ~7sec
system.time(t2(10^6)) # < 1sec

system.time(replicate(10^5, t1(10))) # ~20sec system.time(replicate(10^5, t2(10))) # ~1sec

vQ

Doran, Harold wrote:
> Shubba
>
> I'm confused. Your first post said the result should be c(1,2,3,4,5,6)
> when x and y are combined. The code I sent does that. But here you say
> your result should be c(4,1,2,5,2,3).
>
> What do you want your result to actually be?
>
>
>> -----Original Message-----
>> From: Shubha Vishwanath Karanth [mailto:shubhak_at_ambaresearch.com]
>> Sent: Wednesday, July 23, 2008 9:17 AM
>> To: Doran, Harold; r-help_at_stat.math.ethz.ch
>> Subject: RE: [R] Simple... but...
>>
>> OK,
>>
>> Let x=c(4,2,2)
>> y=c(1,5,3)
>>
>> My result should be c(4,1,2,5,2,3)
>>
>> Thanks, Shubha
>>
>> -----Original Message-----
>> From: Doran, Harold [mailto:HDoran_at_air.org]
>> Sent: Wednesday, July 23, 2008 6:47 PM
>> To: Shubha Vishwanath Karanth; r-help_at_stat.math.ethz.ch
>> Subject: RE: [R] Simple... but...
>>
>> x <- c(1,3,5)
>> y <- c(2,4,6)
>>
>> sort(c(x,y))
>>
>>
>>> -----Original Message-----
>>> From: r-help-bounces_at_r-project.org
>>> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Shubha
>>>
>> Vishwanath
>>
>>> Karanth
>>> Sent: Wednesday, July 23, 2008 8:55 AM
>>> To: r-help_at_stat.math.ethz.ch
>>> Subject: [R] Simple... but...
>>>
>>> Hi R,
>>>
>>>
>>>
>>> If
>>>
>>> x=c(1,3,5)
>>>
>>> y=c(2,4,6)
>>>
>>>
>>>
>>> I need a vector which is c(1,2,3,4,5,6) from x and y.
>>>
>>>
>>>
>>> How do I do it? I mean the best way....
>>>
>>>
>>>
>>> Thanks, Shubha
>>>
>>>
>>>
>>> This e-mail may contain confidential and/or privileged
>>> i...{{dropped:13}}
>>>
>>> ______________________________________________
>>> R-help_at_r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>> This e-mail may contain confidential and/or privileged
>> information. If you are not the intended recipient (or have
>> immediately and destroy this e-mail. Any unauthorized
>> copying, disclosure or distribution of the material in this
>> e-mail is strictly forbidden. Any views or opinions
>> presented are solely those of the author and do not
>> necessarily represent those of Amba Holdings Inc., and/or its
>> affiliates. Important additional terms relating to this
>> email can be obtained at http://www.ambaresearch.com/disclaimer
>>
>>
>>
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.
>

```--
-------------------------------------------------------------------------------
Wacek Kusnierczyk, MD PhD

Email: waku_at_idi.ntnu.no
Phone: +47 73591875, +47 72574609

Department of Computer and Information Science (IDI)
Faculty of Information Technology, Mathematics and Electrical Engineering (IME)
Norwegian University of Science and Technology (NTNU)
Sem Saelands vei 7, 7491 Trondheim, Norway
Room itv303

Bioinformatics & Gene Regulation Group
Department of Cancer Research and Molecular Medicine (IKM)
Faculty of Medicine (DMF)
Norwegian University of Science and Technology (NTNU)
Laboratory Center, Erling Skjalgsons gt. 1, 7030 Trondheim, Norway
Room 231.05.060

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help