vector                 package:base                 R Documentation

_V_e_c_t_o_r_s

_D_e_s_c_r_i_p_t_i_o_n:

     'vector' produces a vector of the given length and mode.

     'as.vector', a generic, attempts to coerce its argument into a
     vector of mode 'mode' (the default is to coerce to whichever mode
     is most convenient).  The attributes of 'x' are removed.

     'is.vector' returns 'TRUE' if 'x' is a vector (of mode logical,
     integer, real, complex, character, raw or list if not specified)
     and 'FALSE' otherwise.

_U_s_a_g_e:

     vector(mode = "logical", length = 0)
     as.vector(x, mode = "any")
     is.vector(x, mode = "any")

_A_r_g_u_m_e_n_t_s:

    mode: A character string giving an atomic mode, or '"any"'.

  length: A non-negative integer specifying the desired length.

       x: An object.

_D_e_t_a_i_l_s:

     'is.vector' returns 'FALSE' if 'x' has any attributes except
     names.  (This is incompatible with S.)  On the other hand,
     'as.vector' removes _all_ attributes including names.

     Note that factors are _not_ vectors;  'is.vector' returns 'FALSE'
     and 'as.vector' converts to character mode.

_V_a_l_u_e:

     For 'vector', a vector of the given length and mode.  Logical
     vector elements are initialized to 'FALSE', numeric vector
     elements to '0', character vector elements to '""', raw vector
     elements to 'nul' bytes and list elements to 'NULL'.

_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:

     'c', 'is.numeric', 'is.list', etc.

_E_x_a_m_p_l_e_s:

     df <- data.frame(x=1:3, y=5:7)
     ## Not run: 
     ## Error:
       as.vector(data.frame(x=1:3, y=5:7), mode="numeric")
     ## End(Not run)

     x <- c(a = 1, b = 2)
     is.vector(x)
     as.vector(x)
     all.equal(x, as.vector(x)) ## FALSE

     ###-- All the following are TRUE:
     is.list(df)
     ! is.vector(df)
     ! is.vector(df, mode="list")

     is.vector(list(), mode="list")
     is.vector(NULL,   mode="NULL")

