Thanks everyone for the solutions !!
Tanvir Ahamed
Göteborg, Sweden | mashra...@yahoo.com
- Original Message -
From: Keith Jewell
To: r-h...@stat.math.ethz.ch
Sent: Wednesday, 22 June 2016, 11:54
Subject: Re: [R] [FORGED] Re: Generate list if sequence form two vector element
or as
or as a one-liner
mapply(pmin(a, b), pmax(a,b), FUN=seq, SIMPLIFY=FALSE)
On 22/06/2016 10:23, peter dalgaard wrote:
There's also
mapply(a, b, FUN=seq, SIMPLIFY=FALSE)
(turn off simplication so that you don't unexpectedly get a matrix whenever all
elements of results have same length. This als
There's also
mapply(a, b, FUN=seq, SIMPLIFY=FALSE)
(turn off simplication so that you don't unexpectedly get a matrix whenever all
elements of results have same length. This also affects apply()-based
solutions.)
...except that according to original spec, one should ensure a < b. So
myseq <-
Now why didn't I think of that?
apply(matrix(c(a,b),ncol=2),1,function(x)x[1]:x[2])
Jim
On Wed, Jun 22, 2016 at 6:14 PM, Rolf Turner wrote:
> 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
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 W
5 matches
Mail list logo