Re: [R] recursive function

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Mon, 14 Jun 2010 15:08:56 -0300

Try this:

transform(x, DELTA = NULL, value = rev(c(5, 5 - cumsum(rev(DELTA[-1])))))

On Mon, Jun 14, 2010 at 12:29 PM, n.vialma_at_libero.it <n.vialma_at_libero.it>wrote:

>
> Dear list,
> I have the following problem, what i'm trying to do is to built a function
> which does the following calculationg in a recursive way:
>
>
> I have a data frame more or less like this:
>
> variable year DELTA
>
> EC01 2006 /
> EC01 2007 10
> EC01 2008 5
> EC01 2009 9
>
>
> And then I have at time 2009 a variable called R_EC01(2009)=5
> What I have to do is to construct the R_EC01 time series by starting from
> the 2009 value:
> R_EC01(2008)=R_EC01(2009)-DELTA(2009)
> R_EC01(2007)=R_EC01(2008)-DELTA(2008)
> R_EC01(2006)=R_EC01(2007)-DELTA(2007)
>
>
> In terms of number, the results that i should get are:
> R_EC01(2008)=5-9=-4
>
> R_EC01(2007)=-4-5=-9
> R_EC01(2006)=-9-10=-19
> so my data frame should looks like this
> SERIES YEAR value
>
> R_EC01 2006 -19
>
> R_EC01 2007 -9
>
> R_EC01 2008 -4
>
> R_EC01 2009 5
> Anyone Knows hot to do it??
> My dataframe is not set as a time series...
>
>
> Thanks a lot!!!
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]


______________________________________________ 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.

Received on Mon 14 Jun 2010 - 18:34:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Jun 2010 - 18:40:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive