Description Usage Arguments See Also Examples
Function toInteger
uses round
followed by
as.integer
to coerce the data part of a
DemographicArray
object to type "integer"
.
Function toDouble
uses as.double
to coerce to type
"double"
. If the coercion to type "integer"
requires
rounding, then an error is raised, unless force
is TRUE
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | toDouble(object)
toInteger(object, force = FALSE)
## S4 method for signature 'DemographicArray'
toDouble(object)
## S4 method for signature 'DemographicArray'
toInteger(object, force = FALSE)
## S4 method for signature 'numeric'
toDouble(object)
## S4 method for signature 'integer'
toInteger(object, force = FALSE)
## S4 method for signature 'numeric'
toInteger(object, force = FALSE)
|
object |
An object of class |
force |
|
as.integer
, which, unlike toInteger
, removes
all attributes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ## A demographic array.
x <- Counts(array(c(1, 2, 3, 4),
dim = c(2, 2),
dimnames = list(sex = c("Female", "Male"),
region = c("a", "b"))))
## x consists entirely of whole numbers,
## but has type "double", not "integer":
is.integer(x)
x <- toInteger(x)
is.integer(x)
x[1] <- 1.1
## rounding is required, so 'toInteger' won't work
## Not run: toInteger(x)
## ...unless 'force' is TRUE
toInteger(x, force = TRUE)
## A numeric vector
x <- c(1, 2, 3)
is.integer(x)
x <- toInteger(x)
x
is.integer(x)
x <- toDouble(x)
x
is.integer(x)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.