Column with codes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Column with codes

MSousa
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

what is the quickest way to create a new column codes
1
1
3
1
1
Reply | Threaded
Open this post in threaded view
|

Odp: Column with codes

PIKAL Petr
Hi
 

> 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
>
> what is the quickest way to create a new column codes
> 1
> 1
> 3
> 1
> 1

Those numbers does not correspond to above mentioned names. If they should
and the.variable is factor

as.numeric(the.variable) produces underlaying numeric values.

Regards
Petr

>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Column-with-
> codes-tp4452906p4452906.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Column with codes

Berend Hasselman
In reply to this post by MSousa

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

Berend

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Odp: Column with codes

MSousa
In reply to this post by PIKAL Petr
It was.

   Thanks

--
View this message in context: http://r.789695.n4.nabble.com/Column-with-codes-tp4452906p4453124.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Column with codes

David Winsemius
In reply to this post by Berend Hasselman

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

______________________________________________
[hidden email] 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.