[R] Column with codes

Berend Hasselman bhh at xs4all.nl
Wed Mar 7 13:11:09 CET 2012


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



More information about the R-help mailing list