[R] factor always have type integer

Berton Gunter gunter.berton at gene.com
Thu Sep 9 00:30:31 CEST 2004


> Therefore, I would like to know if there are other types of variables
> (besides factors) which give a misunderstandable answer about 
> the type 
> of their values when asked typeof.

Your question is a bit combative, don't you think? R performs as documented,
so I think your characterization is inaccurate and certainly unfair, as
software is not required to do what one expects, only what is promised.

I'm not sure what you mean by "misunderstandable" (which I don't believe is
a word, btw). In fact, within R, because of S3 or S4 print/show methods
there is no necessity at all that what is printed out on the screen has
anything to do with what "typeof" will give.?print will give some details
for S3 methods ?show for S4 methods,(provided the class package and
associated Help files are loaded). So in that sense, there are an infinite
number of "variables" (i.e. objects) where there is disagreement.

In the sense that you ask (reading in a rectangular array?) please read
?data.frame and ?ead.table carefully. But it surely must depend on exactly
how you are "importing" the data -- i.e., what R function you are using to
do this. One thing to beware of: how missing data (blanks) in the Excel data
or missing value codes like "NA" or "N/A" are handled. For example,
read.table() will correctly interpret blanks in a text file given the
correct number of field/delimiter specifications; but entries like "N/A" in
a numeric field will be interpreted as characters, so that the numeric field
will be converted to characters and then to factor unless you invoke the
as.is=TRUE parameter (by which you can avoid your suggested ifelse
construction, btw). Thus your typeof() invocation would give integer on what
started off as a floating point column in Excel.

So attention to detail and the software documentation is required! IMHO R's
documentation is excellent, and truly remarkable given that it is an all
volunteer effort. Please take advantage of it.


-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box
 
 


More information about the R-help mailing list