[R] Why is.integer() doesn't work with single values?
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Wed May 29 13:59:54 CEST 2002
Sven Garbade <garbade at psy.uni-muenchen.de> writes:
> Hi all,
>
> I don't understand the behavior of is.integer():
>
> > x <- integer()
> > is.integer(x)
> [1] TRUE
> > x <- 10
> > is.integer(x)
> [1] FALSE
> > x <- 1:10
> > is.integer(x)
> [1] TRUE
>
> Why is.interger() returns FALSE if x has only one element? And how can
> someone check if x is an integer but contains only one value? (R 1.5.0
> on Linux i386)
This has nothing to do with is.integer or lengths. It is the ":"
operator that tries to make its result an integer vector whenever
possible. Constant are generally floating point numbers, even when
they happen to be integers.
Try is.integer(1:1) and is.integer(c(1,2,3)).
--
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