[R] variable name question

David Winsemius dwinsemius at comcast.net
Sun Oct 9 21:01:23 CEST 2011


On Oct 9, 2011, at 2:24 PM, Carlos Ortega wrote:

> Hello,
>
> In R you just need to take the log of the whole whole data.frame  
> where you
> have your pci* and store in a new variable.
> You do not need to use a "for" loop:
>
> log.df <- log(your_data_frame)

Possibly with a selection for the column names in question:

log.pci.df <- log( your_data_frame[ , grep("^pci",  
names(your_data_frame) ) ]

You can also cbind() your identifiers and covariates columns to the  
result.

-- 
David.
>
> Regards,
> Carlos Ortega
> www.qualityexcellence.es
>
>
> On Sun, Oct 9, 2011 at 5:34 PM, deepankar <dbasu at econs.umass.edu>  
> wrote:
>
>> Hi All,
>>
>> This is surely an easy question but somehow I am not being able to  
>> get it.
>>
>> I am using R 2.13.2 and have a data set where variable names like  
>> this
>> appear:
>>
>> pci1990, pci1991, ... , pci2009.
>>
>> "pci1990" has data on per capita income for 1990, "pci1991" has  
>> data on per
>> capita income for 1991, and so on.
>>
>> I would like to create the logarithm of per capita for each of the  
>> year and
>> could do so in STATA with the following commands:
>>
>> forvalues number = 1990/2009 {
>>   gen lpci`number' = log(pci`number')
>> }
>>
>> What would be the corresponding set of commands in R?
>>
>> Thanks a lot in advance.
>>
>> Deepankar
>>
>> ______________________________**________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help 
>> >
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> 	[[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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list