Re: [R] problem with cbind

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Thu 02 Feb 2006 - 08:35:30 EST


That's because:

> as.numeric(factor(c(0, 1)))
[1] 1 2

The underlying representation of a factor, say `x', is to use integers 1 through nlevels(x). If you do anything that simply convert the factor to numeric, you just get these codes.

If you create a data frame (instead of simply cbind()ing them together) you'll retain them as factors.

Andy

From: Ana Patricia Martins
>
> Hello,
>
>
>
> I think this is Sill question but it's happens......
>
>
>
>
>
> am$e_isell <- factor( with( am, ifelse( e_iacc == 1 & C5 == 1, 1, 0)))
>
>
>
> summary (am$e_isell)
>
> 0 1
>
> 3966 296
>
> (Ok)
>
>
>
> am$e_isell [4256]
>
> [1] 1
>
> Levels: 0 1
>
> (OK)
>
>
>
>
>
> cbind( am$e_isell[4256], am$C6[4256])
>
> [,1] [,2]
>
> [1,] "2" "1"
>
> (??)
>
>
>
> cbind( am$e_isell[4256])
>
> [,1]
>
> [1,] "2"
>
> (??)
>
>
>
>
>
> Does anyone understand why this happens?
>
>
>
>
>
> Atenciosamente
>
> Ana Patricia Martins
>
> -------------------------------------------
>
> Serviço Métodos Estatísticos
>
> Departamento de Metodologia Estatística
>
> Telef: 218 426 100 - Ext: 3210
>
> E-mail: <mailto:ana.pmartins@ine.pt> ana.pmartins@ine.pt
>
>
>
>
> [[alternative HTML version deleted]]
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Feb 02 08:42:45 2006

This archive was generated by hypermail 2.1.8 : Thu 02 Feb 2006 - 20:22:07 EST