I am having a similar problem.
If I import data from a ASCII file using import.data, the resulting data
frame has columns which all have the same mode but the actual columns are of
modes character and numeric. In the ASCII file, the character column values
have quotes around them, other columns are simply numbers. The mode of the
columns is always set to numeric. Why? Then, if I change the mode of one to
character, the mode of all columns changes, like Gerald.
Thanks for your help,
Barnali
____________________________________________
Barnali Das
RE461
WESTAT
1650 Research Blvd
Rockville MD 20850
(240)453 2907
DASB@westat.com
www.cgd.ucar.edu/~barnali
____________________________________________
-----Original Message-----
From: Gerald.Jean@spgdag.ca [mailto:Gerald.Jean@spgdag.ca]
Sent: Wednesday, November 29, 2000 10:40 AM
To: s-news@wubios.wustl.edu
Subject: [S] Columns of data.frame converted from numeric to character.
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"
---------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
|