Hi Bert,

thanks for your advice on lapply which I am still not very familair with.
With regard from the issue of the names I realised that I can simply call
names on the data.frame and then join them with other strings through paste
and add them to the data.frame by using the [] syntax rather than the $


Thanks

Paolo



On 19 May 2011 16:53, Bert Gunter <gunter.ber...@gene.com> wrote:

> 1. This won't work. The lagged variables have length one less than the
> originals.
>
> 2. How about:
>
> lagged_Q <- data.frame( lapply( QuarterlyData,diff))
>
> You can then change the names in lagged_Q to something like
> lagged_originalName via paste() if you like.
>
> 3. I strongly suspect that none of this is necessary or wise: R  has
> numerous time series modeling and graphical capabilities that handle
> this automatically. I suggest you first  check the time series Task
> View on CRAN to see if something there already does what you want.
>
> -- Bert
>
> On Thu, May 19, 2011 at 8:05 AM, Paolo Rossi
> <statmailingli...@googlemail.com> wrote:
> > Hello,
> >
> > I would like to create lagged and delta variables from a set of variables
> > and then add them to a dataframe
> >
> > Suppose that GDPPcSa is a variable. I would like to be able to do this
> >
> > QuarterlyData$D1GdpPcSa = diff(GDPPcSa , 1)
> >
> > in an automated fashion so that I loop over Quartely data to compute the
> > first difference  of its variables and add them to the dataframe.
> >
> > .It would be great to get a way to create the string "D1GdpPcSa" knowing
> > that the name of the var is GdpPcSa. Then I can add the varibale
>  D1GdpPcSa
> > to the dataframe and work on its names attribute.
> >
> > Thanks
> >
> > Paolo
> >
> >        [[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.
> >
>
>
>
> --
> "Men by nature long to get on to the ultimate truths, and will often
> be impatient with elementary studies or fight shy of them. If it were
> possible to reach the ultimate truths without the elementary studies
> usually prefixed to them, these would not be preparatory studies but
> superfluous diversions."
>
> -- Maimonides (1135-1204)
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>

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

Reply via email to