[R] Converting Variable Name into String

Bert Gunter gunter.berton at gene.com
Thu May 19 17:53:44 CEST 2011


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



More information about the R-help mailing list