Skip to content

All anchored series from a vector?

4 messages · Gábor Csárdi, Johannes Graumann

#
miracle <- function(x) { lapply(seq(along=x), function(y) x[1:y]) }

Gabor
On Tue, Dec 18, 2007 at 11:40:37PM +0100, Johannes Graumann wrote:

  
    
#
Hi all,

What may be a smart, efficient way to get the following result:

myvector <- c("A","B","C","D","E")
myseries <- miracle(myvector)
myseries
[1]
[[1]] "A"
[2]
[[1]] "A" "B"
[3]
[[1]] "A" "B"
[4]
[[1]] "A" "B" "C"
[5]
[[1]] "A" "B" "C" "D"
[6]
[[1]] "A" "B" "C" "D" "E"

Thanks for any hints,

Joh
#
Should have been:
Sorry, Joh
Johannes Graumann wrote:

            
#
Elegant. Thanks to you too.

Joh
Gabor Csardi wrote: