s-news
[Top] [All Lists]

Columns of data.frame converted from numeric to character.

To: s-news@wubios.wustl.edu
Subject: Columns of data.frame converted from numeric to character.
From: Gerald.Jean@spgdag.ca
Date: Wed, 29 Nov 2000 10:39:58 -0500
Hello S-users,

S+2000, on NT5.0

I have a data.frame with all numeric columns, I convert one of the column
to character depending on the numeric values for that column, the whole
data.frame is converted to character mode, why?  Data.frames are lists and
as such can have columns of different modes, why is this happening in this
case and how do we prevent the conversion of the other columns?

> is.data.frame(ttt)
[1] T

> apply(ttt, 2, FUN =  mode)
     penet         n   success      pull         z      sign
 "numeric" "numeric" "numeric" "numeric" "numeric" "numeric"

> ttt[, 'sign'] <- ifelse(ttt[, 'sign'] == -1, '-',
+                            ifelse(ttt[, 'sign'] == 0, 'N', '+'))

> apply(ttt, 2, FUN =  mode)
       penet           n     success        pull           z        sign
 "character" "character" "character" "character" "character" "character"

> is.data.frame(ttt)
[1] T

Thanks to all,

Gérald Jean
Analyste-conseil (statistiques), Actuariat
télephone            : (418) 835-4900 poste (7639)
télecopieur          : (418) 835-6657
courrier électronique: gerald.jean@spgdag.ca

"In God we trust all others must bring data"


<Prev in Thread] Current Thread [Next in Thread>
  • Columns of data.frame converted from numeric to character., Gerald . Jean <=