[R] (no subject)

David Winsemius dwinsemius at comcast.net
Thu Jan 21 05:17:26 CET 2010


On Jan 20, 2010, at 11:10 PM, Tena Sakai wrote:

> Hi,
>
> When I emulate what's suggested I get an error (shown below).
> What does this mean?
> Thank you.
>
>> Province <- c(1, 1, 13)
>> District <- c(1, 2, 2)
>>
>> df$Distric_Unique <- with(df, paste(Province, District, sep=".") )
> Error in eval(substitute(expr), data, enclos = parent.frame()) :
>  invalid 'envir' argument

You said you had 2 columns, and you wanted something that looked like  
a dataframe, so I assumed you were thinking these were columns of a  
dataframe. I further assumed you would know enough to substitute  
whatever the name of your dataframe might have been for the "df"  
object. Since you don't, all you need to do is:

 > paste(Province, District, sep=".")
[1] "1.1"  "1.2"  "13.2"

>>
>
> Regards,
>
> Tena Sakai
> tsakai at gallo.ucsf.edu
>
>
> On 1/20/10 6:45 PM, "David Winsemius" <dwinsemius at comcast.net> wrote:
>
>>
>> On Jan 20, 2010, at 9:34 PM, teurlai magali wrote:
>>
>>> Hi
>>>
>>> is there a way in R to create a new column vector with the numbers
>>> of 2 others columns simply appended?
>>>
>>> Example : I have a column with provinces codes (1 to 19)
>>> I have a second column with districts codes (1 to ##, depending on
>>> the province)
>>> I want to create a third column with a code that would be unique for
>>> each district:
>>>
>>> Province  District   District_Unique
>>> 1             1            11
>>> 1             2            12
>>> 13           2            132
>>>
>> Better to put in a separator. That way you can tell Prov=1, Distr=11
>> from Prov=11, Distr=1.  Try:
>>
>> df$Distric_Unique <- with(df, paste(Province, District, sep=".") )
>>
>>
>>> I can create a loop, but it becomes complicated with numerous data
>>>
>>> Thanks for your help
>>>
>>>
>>>
>>>
>>>
>>> [[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
>> Heritage Laboratories
>> West Hartford, CT
>>
>> ______________________________________________
>> 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
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list