Skip to content

Behavior of seq with vector from

9 messages · Rowe, Brian Lee Yung (Portfolio Analytics), Ben Bolker, Baptiste Auguie +4 more

#
Rowe, Brian Lee Yung (Portfolio Analytics) wrote:
Don't know if this is "cleaner" or not.
It may be a little bit too tricky.

c(outer(2:3,seq(0,by=3,length.out=4),"+"))

  Can compress your example slightly:

c(t(apply(matrix(2:3), 1, seq, by=3,length.out=4)))
#
Hi,

Perhaps you can try this,
HTH,

baptiste

On 21 May 2009, at 21:08, Rowe, Brian Lee Yung (Portfolio Analytics)  
wrote:
#
Rowe, Brian Lee Yung (Portfolio Analytics) wrote:
....
1. Hmm, not really. NA.

2. I'd view it as an outer sum, stringed out to a single vector, hence:
[1]  2  3  5  6  8  9 11 12
#
So if I want to concatenate the output of multiple seq calls, there's no clear way to to do this?

For background, I have a number of data.frames with the same structure in a list. I want to 'collapse' the list into a single data.frame but only keeping certain columns from each underlying data.frame. In my example below, I want to keep columns 2,3 in each underlying data.frame.

I'm using do.call('cbind', my.list) and then using the statement below to extract only the columns I need (other details omitted for brevity). If there's a built-in or pre-built function to do this, I'm all eyes.


Brian

PS if this is unclear, flame away, and I'll post some code

-----Original Message-----
From: Peter Dalgaard [mailto:P.Dalgaard at biostat.ku.dk] 
Sent: Friday, May 22, 2009 6:20 AM
To: Rowe, Brian Lee Yung (Portfolio Analytics)
Cc: r-help at r-project.org
Subject: Re: [R] Behavior of seq with vector from
Rowe, Brian Lee Yung (Portfolio Analytics) wrote:
....
1. Hmm, not really. NA.

2. I'd view it as an outer sum, stringed out to a single vector, hence:
[1]  2  3  5  6  8  9 11 12
#
Try it this way:

# test list of data frames
L <- list(anscombe[1:4], anscombe[5:8], anscombe[1:4], anscombe[5:8])

# get columns 2 and 3 from each component; cbind those together
do.call(cbind, lapply(L, "[", 2:3))


On Fri, May 22, 2009 at 11:01 AM, Rowe, Brian Lee Yung (Portfolio
Analytics) <B_Rowe at ml.com> wrote:
#
##Is this what you mean ??

do.call(rbind,lapply(yourlist,"[",,seq(from=1,by=3,length=4)))

## note the ",," that omits the row argument in the call to "["

-- Bert Gunter
Genentech Nonclinical Biostatistics

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Rowe, Brian Lee Yung (Portfolio Analytics)
Sent: Friday, May 22, 2009 8:02 AM
To: Peter Dalgaard
Cc: r-help at r-project.org
Subject: Re: [R] Behavior of seq with vector from

So if I want to concatenate the output of multiple seq calls, there's no
clear way to to do this?

For background, I have a number of data.frames with the same structure in a
list. I want to 'collapse' the list into a single data.frame but only
keeping certain columns from each underlying data.frame. In my example
below, I want to keep columns 2,3 in each underlying data.frame.

I'm using do.call('cbind', my.list) and then using the statement below to
extract only the columns I need (other details omitted for brevity). If
there's a built-in or pre-built function to do this, I'm all eyes.


Brian

PS if this is unclear, flame away, and I'll post some code

-----Original Message-----
From: Peter Dalgaard [mailto:P.Dalgaard at biostat.ku.dk] 
Sent: Friday, May 22, 2009 6:20 AM
To: Rowe, Brian Lee Yung (Portfolio Analytics)
Cc: r-help at r-project.org
Subject: Re: [R] Behavior of seq with vector from
Rowe, Brian Lee Yung (Portfolio Analytics) wrote:
....
1. Hmm, not really. NA.

2. I'd view it as an outer sum, stringed out to a single vector, hence:
[1]  2  3  5  6  8  9 11 12
#
Brilliant! Thanks, Brian

-----Original Message-----
From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com] 
Sent: Friday, May 22, 2009 11:20 AM
To: Rowe, Brian Lee Yung (Portfolio Analytics)
Cc: Peter Dalgaard; r-help at r-project.org
Subject: Re: [R] Behavior of seq with vector from


Try it this way:

# test list of data frames
L <- list(anscombe[1:4], anscombe[5:8], anscombe[1:4], anscombe[5:8])

# get columns 2 and 3 from each component; cbind those together
do.call(cbind, lapply(L, "[", 2:3))


On Fri, May 22, 2009 at 11:01 AM, Rowe, Brian Lee Yung (Portfolio
Analytics) <B_Rowe at ml.com> wrote: