matrix                 package:base                 R Documentation

_M_a_t_r_i_c_e_s

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

     'matrix' creates a matrix from the given set of values.

     'as.matrix' attempts to turn its argument into a matrix.

     'is.matrix' tests if its argument is a (strict) matrix. It is
     generic: you can write methods to handle specific classes of
     objects, see InternalMethods.

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

     matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL)
     as.matrix(x)
     is.matrix(x)

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

    data: an optional data vector.

    nrow: the desired number of rows

    ncol: the desired number of columns

   byrow: logical. If 'FALSE' (the default) the matrix is filled by
          columns, otherwise the matrix is filled by rows.

dimnames: A 'dimnames' attribute for the matrix: a 'list' of length 2.

       x: an R object.

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

     If either of 'nrow' or 'ncol' is not given, an attempt is made to
     infer it from the length of 'data' and the other parameter.

     If there are too few elements in 'data' to fill the array, then
     the elements in 'data' are recycled.  If 'data' has length zero,
     'NA' of an appropriate type is used for atomic vectors and 'NULL'
     for lists.

     'is.matrix' returns 'TRUE' if 'x' is a matrix (i.e., it is _not_ a
     'data.frame' and has a 'dim' attribute of length 2) and 'FALSE'
     otherwise.

     'as.matrix' is a generic function. The method for data frames will
     convert any non-numeric/complex column into a character vector
     using 'format' and so return a character matrix, except that
     all-logical data frames will be coerced to a logical matrix.

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

     'data.matrix', which attempts to convert to a numeric matrix.

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

     is.matrix(as.matrix(1:10))
     data(warpbreaks)
     !is.matrix(warpbreaks)# data.frame, NOT matrix!
     warpbreaks[1:10,]
     as.matrix(warpbreaks[1:10,]) #using as.matrix.data.frame(.) method

