Re: [R] NA in table with integer types

2005-04-08 Thread Prof Brian Ripley
NaN only applies to double values: there is no integer NaN (nor Inf nor 
-Inf).  The difference is clear from

factor(x, exclude=NaN)
[1] 1233NA
Levels: 1 2 3 NA
factor(as.integer(x), exclude=NaN)
[1] 1233NA
Levels: 1 2 3
If you read ?factor it says
 exclude: a vector of values to be excluded when forming the set of
  levels. This should be of the same type as 'x', and will be
  coerced if necessary.
and as.integer(NaN) is integer NA.  So  factor(as.integer(x), exclude=NaN) 
is the same as  factor(as.integer(x), exclude=NA).

On Thu, 7 Apr 2005, 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=NaN will not do it.  See below, where x is double at
first, and then coerced to integer and notice the difference.  Is this a
bug or is there something that I do not understand about the integer data
type?  That is, is there some other value besides NA and NaN that missing
integers take? 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
  123 NA
  1121
table(x,exclude=NULL)
x
  123 NA
  1121
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
  123 NA
  1121
--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] NA in table with integer types

2005-04-08 Thread Paul Rathouz

OK.  Thanks.  So, if you use table() on a factor that contains NA's, but
for which NA is not a level, is there any way to get table to generate an
entry for the NAs?  For example, in below, even exclude=NULL will not
give me an entry for NA on the factor y:

 x - c(1,2,3,3,NA)
 y - factor(x)
 y
[1] 1233NA
Levels: 1 2 3
 table(y,exclude=NA)
y
1 2 3
1 1 2
 table(y,exclude=NaN)
y
1 2 3
1 1 2
 table(y,exclude=NULL)
y
1 2 3
1 1 2

On Fri, 8 Apr 2005, Prof Brian Ripley wrote:

 NaN only applies to double values: there is no integer NaN (nor Inf nor
 -Inf).  The difference is clear from

  factor(x, exclude=NaN)
 [1] 1233NA
 Levels: 1 2 3 NA
  factor(as.integer(x), exclude=NaN)
 [1] 1233NA
 Levels: 1 2 3

 If you read ?factor it says

   exclude: a vector of values to be excluded when forming the set of
levels. This should be of the same type as 'x', and will be
coerced if necessary.

 and as.integer(NaN) is integer NA.  So  factor(as.integer(x), exclude=NaN)
 is the same as  factor(as.integer(x), exclude=NA).


[rest deleted]

==
Paul Rathouz, Assoc. Professor   ph   773-834-1970
Dept. of Health Studies, Rm. W-264   fax  773-702-1979
University of Chicago[EMAIL PROTECTED]
5841 S. Maryland Ave. MC 2007
Chicago, IL  60637

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] NA in table with integer types

2005-04-08 Thread Gabor Grothendieck
On Apr 8, 2005 9:05 AM, Paul Rathouz [EMAIL PROTECTED] wrote:
 
 OK.  Thanks.  So, if you use table() on a factor that contains NA's, but
 for which NA is not a level, is there any way to get table to generate an
 entry for the NAs?  For example, in below, even exclude=NULL will not
 give me an entry for NA on the factor y:
 
  x - c(1,2,3,3,NA)
  y - factor(x)
  y
 [1] 1233NA
 Levels: 1 2 3

summary(y)

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] NA in table with integer types

2005-04-08 Thread Prof Brian Ripley
On Fri, 8 Apr 2005, Paul Rathouz wrote:
OK.  Thanks.  So, if you use table() on a factor that contains NA's, but
for which NA is not a level, is there any way to get table to generate an
entry for the NAs?  For example, in below, even exclude=NULL will not
give me an entry for NA on the factor y:
I think this very clear from the help page:
 exclude: values to use in the exclude argument of 'factor' when
  interpreting non-factor objects; if specified, levels to
  remove from all factors in 
 Only when 'exclude' is specified (i.e., not by default), will
 'table' drop levels of factor arguments potentially.
and you cannot remove a level that is not there.
You seem to be persisting in not understanding: 'exclude' is supposed to 
be the same type as x (or its levels), and you have given logical and 
numeric values, not character ones.


x - c(1,2,3,3,NA)
y - factor(x)
y
[1] 1233NA
Levels: 1 2 3
table(y,exclude=NA)
y
1 2 3
1 1 2
table(y,exclude=NaN)
y
1 2 3
1 1 2
table(y,exclude=NULL)
y
1 2 3
1 1 2
On Fri, 8 Apr 2005, Prof Brian Ripley wrote:
NaN only applies to double values: there is no integer NaN (nor Inf nor
-Inf).  The difference is clear from
factor(x, exclude=NaN)
[1] 1233NA
Levels: 1 2 3 NA
factor(as.integer(x), exclude=NaN)
[1] 1233NA
Levels: 1 2 3
If you read ?factor it says
  exclude: a vector of values to be excluded when forming the set of
   levels. This should be of the same type as 'x', and will be
   coerced if necessary.
and as.integer(NaN) is integer NA.  So  factor(as.integer(x), exclude=NaN)
is the same as  factor(as.integer(x), exclude=NA).
[rest deleted]
==
Paul Rathouz, Assoc. Professor   ph   773-834-1970
Dept. of Health Studies, Rm. W-264   fax  773-702-1979
University of Chicago[EMAIL PROTECTED]
5841 S. Maryland Ave. MC 2007
Chicago, IL  60637
==

--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] NA in table with integer types

2005-04-08 Thread Petr Pikal


On 8 Apr 2005 at 14:20, Prof Brian Ripley wrote:

 On Fri, 8 Apr 2005, Paul Rathouz wrote:
 
 
  OK.  Thanks.  So, if you use table() on a factor that contains NA's,
  but for which NA is not a level, is there any way to get table to
  generate an entry for the NAs?  For example, in below, even
  exclude=NULL will not give me an entry for NA on the factor y:

Hi

Use exclude in factor not in table

 x-sample(1:3, 10, replace=T)
 x[5:6]-NA
 table(x)
x
1 2 3 
5 2 1 
 y-factor(x)
 y
 [1] 1123NA NA 1121   
Levels: 1 2 3
 table(y) # no entry for NA
y
1 2 3 
5 2 1 
 factor(y,exclude=NULL) #make NA a level in factor y
 [1] 1123NA NA 1121   
Levels: 1 2 3 NA

 table(y) # shows you entry for NA
y
   123 NA 
   5212 





 
 I think this very clear from the help page:
 
   exclude: values to use in the exclude argument of 'factor' when
interpreting non-factor objects; if specified, levels to
remove from all factors in 
 
   Only when 'exclude' is specified (i.e., not by default), will
   'table' drop levels of factor arguments potentially.
 
 and you cannot remove a level that is not there.
 
 You seem to be persisting in not understanding: 'exclude' is supposed
 to be the same type as x (or its levels), and you have given logical
 and numeric values, not character ones.
 
 
 
  x - c(1,2,3,3,NA)
  y - factor(x)
  y
  [1] 1233NA
  Levels: 1 2 3
  table(y,exclude=NA)
  y
  1 2 3
  1 1 2
  table(y,exclude=NaN)
  y
  1 2 3
  1 1 2
  table(y,exclude=NULL)
  y
  1 2 3
  1 1 2
 
  On Fri, 8 Apr 2005, Prof Brian Ripley wrote:
 
  NaN only applies to double values: there is no integer NaN (nor Inf
  nor -Inf).  The difference is clear from
 
  factor(x, exclude=NaN)
  [1] 1233NA
  Levels: 1 2 3 NA
  factor(as.integer(x), exclude=NaN)
  [1] 1233NA
  Levels: 1 2 3
 
  If you read ?factor it says
 
exclude: a vector of values to be excluded when forming the set
of
 levels. This should be of the same type as 'x', and will
 be coerced if necessary.
 
  and as.integer(NaN) is integer NA.  So  factor(as.integer(x),
  exclude=NaN) is the same as  factor(as.integer(x), exclude=NA).
 
 
  [rest deleted]
 
  
  == Paul Rathouz, Assoc. Professor   ph   773-834-1970 Dept.
  of Health Studies, Rm. W-264   fax  773-702-1979 University of
  Chicago[EMAIL PROTECTED] 5841 S.
  Maryland Ave. MC 2007 Chicago, IL  60637
  
  ==
 
 
 
 -- 
 Brian D. Ripley,  [EMAIL PROTECTED]
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self) 1 South
 Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG,
 UKFax:  +44 1865 272595
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html

Petr Pikal
[EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] NA in table with integer types

2005-04-07 Thread Paul Rathouz

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=NaN will not do it.  See below, where x is double at
first, and then coerced to integer and notice the difference.  Is this a
bug or is there something that I do not understand about the integer data
type?  That is, is there some other value besides NA and NaN that missing
integers take? 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
   123 NA
   1121
 table(x,exclude=NULL)
x
   123 NA
   1121

 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
   123 NA
   1121

 R.version
 _
platform powerpc-apple-darwin6.8
arch powerpc
os   darwin6.8
system   powerpc, darwin6.8
status
major2
minor0.1
year 2004
month11
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[EMAIL PROTECTED]
5841 S. Maryland Ave. MC 2007
Chicago, IL  60637

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html