Two general R tips:

1) Don't name variables seq or var. These are two really important R
functions and you can get all sorts of unexpected craziness if you overload
them. Going forward, also watch out for t,c, T, F as well.

2) As others have noted, it's very possible to implement this without an
explicit for loop. You should work on doing that to increase speed. It won't
be noticeable here, but will make all the difference in the world as you
start writing more complex code. If you want to give it a shot, just see
what you can do and write back (off-list perhaps) if you need a hint or
someone to check your work and I'll happily give you a hand.

Michael

On Mon, Aug 22, 2011 at 10:10 PM, Claudio Zanettini <
claudio.zanettini@gmail.com> wrote:

> I definitely used too much lines s of code because I still don't know how
> to
> do some staff.
> but it works:
> seq=5         #starting value
> var=5        # starting value
> long= 1:10   # length of the vector
> for (x in long){
>        var=var+((var/100)*40)
>    seq=append(seq,var)
> }
> seq=round(seq)
> seq=cumsum(seq)
>
> > seq
>  [1]    5   17   39   75  130  212  332  505  752 1102 1597
>
>
> Probably I could set just a variable instead of 2 ( var and seq)
> and set the value of long directly to 10, but as I said I just started
> using
> R
>
>
> Thanks :)
>
> ?cumsum
> > cumsum(yoursequence)
> >
> > HTH,
> > Jorge
> >
> >
> > On Mon, Aug 22, 2011 at 8:36 PM, Claudio Zanettini <> wrote:
> >
> >> Hello everyone,
> >> I would like to generate a sequence
> >> such as, starting from 5, every value  is
> >>  40% of the value before+ all the preceeding values.
> >> es:
> >> this is the seq of all the value+40% of the preceding value:
> >> 5         7        10        14        19        27        38
> >> 53        74       103       145       202       283       397
> >> 556       778      1089      1525      2134      2988      4183
> >>
> >> then the vector tha I need is
> >>  5 , 5+7, 5+7+10, 5+7+10+14 and so on
> >>
> >> I can generate the first sequence but I don t know how to generate the
> >> last.
> >>
> >> I would really appreciate your help.
> >> Thanks
> >> HVZ
> >>
> >>        [[alternative HTML version deleted]]
> >>
> >> ______________________________________________
> >> R-help@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.
> >>
> >
> >
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]

