names                  package:base                  R Documentation

_T_h_e _N_a_m_e_s _A_t_t_r_i_b_u_t_e _o_f _a_n _O_b_j_e_c_t

_D_e_s_c_r_i_p_t_i_o_n:

     Functions to get or set the names of an object.

_U_s_a_g_e:

     names(x)
     names(x) <- value

_A_r_g_u_m_e_n_t_s:

       x: an R object.

   value: a character vector of up to the same length as 'x', or
          'NULL'.

_D_e_t_a_i_l_s:

     'names' is a generic accessor function, and 'names<-' is a generic
     replacement function.  The default methods get and set the
     '"names"' attribute of a vector or list.

     If 'value' is shorter than 'x', it is extended by character 'NA's
     to the length of 'x'.

     It is possible to update just part of the names attribute via the
     general rules: see the examples.  This works because the
     expression there is evaluated as 'z <- "names<-"(z,
     "[<-"(names(z), 3, "c2"))'.

     The name '""' is special: it is used to indicate that there is no
     name associated with an element of a (atomic or generic) vector.
     Subscripting by '""' will match nothing (not even elements which
     have no name).

_V_a_l_u_e:

     For 'names', 'NULL' or a character vector of the same length as
     'x'.

     For 'names<-', the updated object.  (Note that the value of
     'names(x) <- value' is that of the assignment, 'value', not the
     return value from the left-hand side.)

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

_E_x_a_m_p_l_e_s:

     # print the names attribute of the islands data set
     names(islands)

     # remove the names attribute
     names(islands) <- NULL
     islands
     rm(islands) # remove the copy made

     z <- list(a=1, b="c", c=1:3)
     names(z)
     # change just the name of the third element.
     names(z)[3] <- "c2"
     z

     z <- 1:3
     names(z)
     ## assign just one name
     names(z)[2] <- "b"
     z

