Re: [R] Converting Variable Name into String

From: Bert Gunter <gunter.berton_at_gene.com>
Date: Thu, 19 May 2011 08:53:44 -0700

  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.

On Thu, May 19, 2011 at 8:05 AM, Paolo Rossi <statmailinglists_at_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_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.
>

-- 
"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

______________________________________________
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 Thu 19 May 2011 - 15:59:00 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Thu 19 May 2011 - 23:20:09 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