Skip to content
Back to formatted view

Raw Message

Message-ID: <84682533-cc76-0497-af00-6abf2206cc13@auckland.ac.nz>
Date: 2016-06-22T08:14:34Z
From: Rolf Turner
Subject: [FORGED] Re: Generate list if sequence form two vector element
In-Reply-To: <CA+8X3fWgvz-qp+jNVHBwwmduHh++HuPqosgEZSwqGfNuMTFWLg@mail.gmail.com>

On 22/06/16 20:00, Jim Lemon wrote:
> Hi Tanvir,
> Not at all elegant, but:
>
> make.seq<-function(x) return(seq(x[1],x[2]))
> apply(matrix(c(a,b),ncol=2),1,make.seq)

Not sure that this is more "elegant" but it's a one-liner:

  lapply(1:length(a),function(i,a,b){a[i]:b[i]},a=a,b=b)

cheers,

Rolf

> On Wed, Jun 22, 2016 at 5:32 PM, Mohammad Tanvir Ahamed via R-help
> <r-help at r-project.org> wrote:
>> Hi,
>> I want to do the follow thing
>>
>> Input :
>> a <- c(1,3,6,9)
>>
>>
>> b<-c(10,7,20,2)
>>
>>
>> Expected outcome :
>>
>> d<-list(1:10,3:7,6:20,2:9)