[R] how to change data type in data frame?

Auston Wei wwei at mdanderson.org
Mon Oct 4 22:48:10 CEST 2004


Liaw, Andy <andy_liaw <at> merck.com> writes:

> 
> Here's one way:
> 
> > temp <- as.matrix(trash)
> > temp[temp=='b'] <- 1
> > temp[temp=='a'] <- 0
> > temp <- as.data.frame(structure(as.numeric(temp), dim=dim(trash),
> dimnames=dimnames(trash)))
> > temp
>   age typeI typeII
> 1   1     0      1
> 2   2     0      0
> 3   3     1      1
> 4   4     0      1
> 5   5     1      0
> 
> HTH,
> Andy
> 

Thank you very much, Andy. It works. Yet another question, what if I want to 
keep age as a factor? Is it possible?

thank you,
Auston




More information about the R-help mailing list