[R-SIG-Mac] NA in table with integer types
Don MacQueen
macq at llnl.gov
Thu Apr 7 21:18:55 CEST 2005
?table tells you that the exclude argument tells it what to exclude.
So of course, NA will not be shown in the output if you supply
exclude=NA. exclude=NULL tells it to exclude nothing, hence NAs are
shown.
This is not a Mac-specific question, by the way, so R-help would have
been the place to ask.
-Don
At 2:11 PM -0500 4/7/05, Paul Rathouz wrote:
>Hi -- I am having the following problem with table() when applied to
>vectors of type (mode) integer. When I use the table() command, I can
>only obtain an entry in the table for NA values by using exclude=NULL.
>Just issuing exclude=NA will not do it. See below, where x is double at
>first, and then integer and notice the difference. Is this a bug or is
>there something that I do not understand about the integer data type?
>Thanks -- pr
>
>------------------------------
>> x <- c(1,2,3,3,NA)
>> is.double(x)
>[1] TRUE
>> table(x,exclude=NA)
>x
>1 2 3
>1 1 2
>> table(x,exclude=NaN)
>x
> 1 2 3 <NA>
> 1 1 2 1
>> table(x,exclude=NULL)
>x
> 1 2 3 <NA>
> 1 1 2 1
>>
>> x <- as.integer(x)
>> x
>[1] 1 2 3 3 NA
>> is.na(x)
>[1] FALSE FALSE FALSE FALSE TRUE
>> is.integer(x)
>[1] TRUE
>> table(x,exclude=NA)
>x
>1 2 3
>1 1 2
>> table(x,exclude=NaN)
>x
>1 2 3
>1 1 2
>> table(x,exclude=NULL)
>x
> 1 2 3 <NA>
> 1 1 2 1
>>
>> R.version
> _
>platform powerpc-apple-darwin6.8
>arch powerpc
>os darwin6.8
>system powerpc, darwin6.8
>status
>major 2
>minor 0.1
>year 2004
>month 11
>day 15
>language R
>------------------------------
>
>==========================================================================
>Paul Rathouz, Assoc. Professor ph 773-834-1970
>Dept. of Health Studies, Rm. W-264 fax 773-702-1979
>University of Chicago prathouz at health.bsd.uchicago.edu
>5841 S. Maryland Ave. MC 2007
>Chicago, IL 60637
>
>_______________________________________________
>R-SIG-Mac mailing list
>R-SIG-Mac at stat.math.ethz.ch
>https://stat.ethz.ch/mailman/listinfo/r-sig-mac
--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
More information about the R-SIG-Mac
mailing list