dim                   package:base                   R Documentation

_D_i_m_e_n_s_i_o_n_s _o_f _a_n _O_b_j_e_c_t

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

     Retrieve or set the dimension of an object.

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

     dim(x)
     dim(x) <- value

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

       x: an R object, for example a matrix, array or data frame.

   value: For the default method, either 'NULL' or a numeric vector,
          which is coerced to integer (by truncation).

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

     The functions 'dim' and 'dim<-' are generic.

     'dim' has a method for 'data.frame's, which returns the lengths of
     the 'row.names' attribute of 'x' and of 'x' (as the numbers of
     rows and columns respectively).

     These functions are primitive, so argument names are ignored (but
     this might not be true of their methods).

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

     For an array (and hence in particular, for a matrix) 'dim'
     retrieves the 'dim' attribute of the object.  It is 'NULL' or a
     vector of mode 'integer'.

     The replacement method changes the '"dim"' attribute (provided the
     new value is compatible) and removes any '"dimnames"' _and_
     '"names"' attributes.

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

     'ncol', 'nrow' and 'dimnames'.

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

     x <- 1:12 ; dim(x) <- c(3,4)
     x

     # simple versions of nrow and ncol could be defined as follows
     nrow0 <- function(x) dim(x)[1]
     ncol0 <- function(x) dim(x)[2]

