A couple days ago, Mark Leeds asked about a solution that would  
basically stagger two lists, a and b, to return a list in the form of  
a[1], b[1], a[2], b[2], a[3]....  In particular, the summary of his  
question was in reference to lists defined by

  x <- 5
  tempin <- seq(1,1411, by=30)
  a <- tempin
  b <- tempin + x

I offered the following function

  everyOther <- function(tempin, x){
  	tempout <- array(data=NA, dim=length(tempin)*2)
  	tempout[seq(1,length(tempin)*2, by=2)]<-tempin
  	tempout[seq(2,length(tempin)*2, by=2)]<-tempin+x
  	tempout
  }

which did what it was supposed to, and Gavin Simpson offered a  
similar function.  Peter Dalgaard, however, supplied a much more  
elegant solution:

  c(rbind(tempin,tempin+5))

or

  rep(tempin, each=2) + c(0,5)

I thought I'd bring this up as a new topic because it's really no  
longer related to what Mark first asked, but is there a way, perhaps  
from the documentation, that a user would know that c() and lists in  
general behave as they do in these two lines?  Or would we just need  
to dig into the code?

I am reminded of quote by Byron Ellis: "Contrary to popular belief  
the speed of R's interpreter is rarely the limiting factor to R's  
speed. People treating R like C is typically the limiting factor. You  
have vector operations, USE THEM."  Not exactly the point, but close.

Thanks!

Jeff Spies
http://www.nd.edu/~jspies/


	[[alternative HTML version deleted]]

