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).

     'is.vector' returns 'TRUE' if 'x' is a vector (of mode logical,
     integer, real, complex, character, raw or list if not specified)
     or expression 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 '"list"', or (not
          for 'vector') '"any"'.

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

       x: An object.

_D_e_t_a_i_l_s:

     The atomic modes are '"logical"', '"integer"', '"numeric"',
     '"complex"', '"character"' and '"raw"'.

     '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 for results
     of atomic mode.

     Note that factors are _not_ vectors;  'is.vector' returns 'FALSE'
     and 'as.vector' converts to a character vector for 'mode = "any"'.

_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'.

     All attributes are removed from the answer if it is of an atomic
     mode.

_N_o_t_e:

     'as.vector' and 'is.vector' are quite distinct from the meaning of
     the formal class '"vector"' in the 'methods' package, and hence
     'as(x, "vector")' and 'is(x, "vector")'.

     'mode's of '"symbol"', '"pairlist"' and '"expression"' are allowed
     but have long been undocumented.

_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")

