integer                 package:base                 R Documentation

_I_n_t_e_g_e_r _V_e_c_t_o_r_s

_D_e_s_c_r_i_p_t_i_o_n:

     Creates or tests for objects of type '"integer"'.

_U_s_a_g_e:

     integer(length = 0)
     as.integer(x, ...)
     is.integer(x)

_A_r_g_u_m_e_n_t_s:

  length: desired length.

       x: object to be coerced or tested.

     ...: further arguments passed to or from other methods.

_D_e_t_a_i_l_s:

     Integer vectors exist so that data can be passed to C or Fortran
     code which expects them, and so that small integer data can be
     represented exactly and compactly.

     Note that on almost all implementations of R the range of
     representable integers is restricted to about +/-2*10^9: 'double's
     can hold much larger integers exactly.

_V_a_l_u_e:

     'integer' creates a integer vector of the specified length. Each
     element of the vector is equal to '0'.

     'as.integer' attempts to coerce its argument to be of integer
     type. The answer will be 'NA' unless the coercion succeeds. Real
     values larger in modulus than the largest integer are coerced to
     'NA' (unlike S which gives the most extreme integer of the same
     sign). Non-integral numeric values are truncated towards zero
     (i.e., 'as.integer(x)' equals 'trunc(x)' there), and imaginary
     parts of complex numbers are discarded (with a warning). Like
     'as.vector' it strips attributes including names.

     'is.integer' returns 'TRUE' or 'FALSE' depending on whether its
     argument is of integer type or not. 'is.integer' is generic: you
     can write methods to handle specific classes of objects, see
     InternalMethods. There is a method for factors which returns
     'FALSE'. (Prior to R 2.0.0, there was no such method and for most
     (but not all) factors 'is.integer' returned 'TRUE'.)

_R_e_f_e_r_e_n_c_e_s:

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

_S_e_e _A_l_s_o:

     'round' (and 'ceiling' and 'floor' on that help page) to convert
     to integral values.

_E_x_a_m_p_l_e_s:

       ## as.integer() truncates:
       x <- pi * c(-1:1,10)
       as.integer(x)

