Coerces a random variable to an integer-valued (discrete) one

# S3 method for rv
as.integer(x, ...)

Arguments

x

an rv object

...

Further arguments passed on

Details

In effect, the function as.integer is applied to all simulations.

Note

is.integer(x) returns TRUE if and only if each component of x is integer-valued (each simulation vector is of type 'integer').

References

Kerman, J. and Gelman, A. (2007). Manipulating and Summarizing Posterior Simulations Using Random Variable Objects. Statistics and Computing 17:3, 235-244.

See also vignette("rv").

See also

Author

Jouni Kerman jouni@kerman.com

Examples


  x <- rvpois(lambda=3)   # some integer-valued random variable
  print(x)
#>     mean  sd 1% 2.5% 25% 50% 75% 97.5% 99% sims
#> [1]    3 1.7  0    0   2   3   4     7   7 4000
  is.integer(x)           # FALSE, because by default x is 'double'!
#> [1] FALSE
  x <- as.integer(x)      # coerce to integer
  is.integer(x)           # TRUE
#> [1] FALSE
  print(x)                # Shows also the 'min' and 'max' columns
#>     mean  sd 1% 2.5% 25% 50% 75% 97.5% 99% sims
#> [1]    3 1.7  0    0   2   3   4     7   7 4000