[R] Column with codes

David Winsemius dwinsemius at comcast.net
Wed Mar 7 14:44:24 CET 2012


On Mar 7, 2012, at 7:11 AM, Berend Hasselman wrote:

>
> On 07-03-2012, at 12:09, RMSOPS wrote:
>
>> Good Day,
>>
>>  I have a small question, I think it is simple to solve,
>>
>> I have a column with the following records
>>
>> name
>> saucer
>> cup
>> tea
>> saucer
>> saucer
>>
>
> I assume that name is a column header. Otherwise the following makes  
> no sense.
>
>> what is the quickest way to create a new column codes
>> 1
>> 1
>> 3
>> 1
>> 1
>
> I assume that the second 1 here is actually intended to be a 2.
>
> Maybe:
>
> as.numeric(factor(x,levels=(c("saucer","cup","tea"))))

Oh, what the heck. I will add yet a third guess .... that  you wanted:

table(name)

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list