>From: Johannes Graumann <johannes_graumann at web.de> >Date: 2007/12/18 Tue PM 04:40:37 CST >To: r-help at stat.math.ethz.ch >Subject: [R] All anchored series from a vector?lapply(1:length(myvector) function(.length) { c(myvector[1}:myvector[.length]) }) but test it because i didn't.>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 > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.
>From: markleeds at verizon.net >Date: 2007/12/18 Tue PM 02:50:52 CST >To: Johannes Graumann <johannes_graumann at web.de> >Cc: r-help at r-project.org >Subject: Re: [R] All anchored series from a vector?i'm sorry. i tested it afterwards and of course it had some problems. below is the working version. myvector<-c("A","B","C","D","E") result<- lapply(1:length(myvector), function(.length) { myvector[1:.length] }) print(result)>>From: Johannes Graumann <johannes_graumann at web.de> >>Date: 2007/12/18 Tue PM 04:40:37 CST >>To: r-help at stat.math.ethz.ch >>Subject: [R] All anchored series from a vector? > >lapply(1:length(myvector) function(.length) { >c(myvector[1}:myvector[.length]) >}) > >but test it because i didn't. > > > >>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 >> >>______________________________________________ >>R-help at r-project.org mailing list >>https://stat.ethz.ch/mailman/listinfo/r-help >>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>and provide commented, minimal, self-contained, reproducible code. > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.
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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Csardi Gabor <csardi at rmki.kfki.hu> MTA RMKI, ELTE TTK
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:> myvector <- c("A","B","C","D","E") > myseries <- miracle(myvector) > myseries > [1] > [[1]] "A" > [2] > [[1]] "A" "B" > [3] > [[1]] "A" "B" "C" > [4] > [[1]] "A" "B" "C" "D" > [5] > [[1]] "A" "B" "C" "D" "E"Sorry, Joh 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 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html and provide commented, > minimal, self-contained, reproducible code.
Debugged version:
lapply(1:length(myvector), function(.length) {
myvector[1:.length]
})
Thanks for showing the direction!
Joh
markleeds at verizon.net wrote:
>>From: Johannes Graumann <johannes_graumann at web.de>
>>Date: 2007/12/18 Tue PM 04:40:37 CST
>>To: r-help at stat.math.ethz.ch
>>Subject: [R] All anchored series from a vector?
>
> lapply(1:length(myvector) function(.length) {
> c(myvector[1}:myvector[.length])
> })
>
> but test it because i didn't.
>
>
>
>>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
>>
>>______________________________________________
>>R-help at r-project.org mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide
>>http://www.R-project.org/posting-guide.html and provide commented,
>>minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented,
> minimal, self-contained, reproducible code.
Elegant. Thanks to you too. Joh Gabor Csardi wrote:> 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 >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html and provide commented, >> minimal, self-contained, reproducible code. >