[R] read.table and factor
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Mon Feb 21 10:41:39 CET 2000
Bill Simpson <wsi at gcal.ac.uk> writes:
> I have a data file like this:
>
> std cf hit miss fa cr
> 920 980 40 15 14 31
> 950 1010 24 23 23 30
> 1190 1250 26 21 27 26
> 1010 1070 33 10 28 29
> 1040 1100 35 10 11 44
>
> I use read.table to read it in. My problem is that read.table makes std
> and cf into factors. I want them just to be ordinary numeric variables.
>
> as.numeric(d$std) doesn't work properly (as the docs warn), and same goes
> for codes(d$std)
as.numeric(as.character()) should do it
> How can I either tell read.table to leave the first two cols as numeric
> (not factors) or convert them from factors into the proper numeric values?
If they're not read as numeric, then they must contain non-numeric
elements. Either fix the typo (!) or set na.strings in the call to
read.table.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list