Matrix                package:Matrix                R Documentation

_C_o_n_s_t_r_u_c_t _a _C_l_a_s_s_e_d _M_a_t_r_i_x

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

     Construct a Matrix of a class that inherits from 'Matrix'.

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

     Matrix(data=NA, nrow=1, ncol=1, byrow=FALSE, dimnames=NULL,
            sparse = NULL)

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

    data: an optional numeric data vector or matrix.

    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 two
          character components.  They are set if not 'NULL' (as per
          default).

  sparse: logical or 'NULL', specifying if the result should be sparse
          or not.  By default, it is made sparse when more than half of
          the entries are 0.

_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.
     Further, 'Matrix()' makes efforts to keep 'logical' matrices
     logical, i.e., inheriting from class 'lMatrix', and to determine
     specially structured matrices such as symmetric, triangular or
     diagonal ones.  Note that a _symmetric_ matrix also needs
     symmetric 'dimnames', e.g., by specifying 'dimnames =
     list(NULL,NULL)', see the examples.

     Although it is sometime possible to mix unclassed matrices
     (created with 'matrix') with ones of class '"Matrix"', it is much
     safer to always use carefully constructed ones of class
     '"Matrix"'.

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

     Returns an 'nrow' by 'ncol' matrix of a class that inherits from
     '"Matrix"'.

_S_e_e _A_l_s_o:

     The classes 'Matrix', 'symmetricMatrix', 'triangularMatrix', and
     'diagonalMatrix'; further, 'matrix'.

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

     Matrix(0, 3, 2)             # 3 by 2 matrix of zeros -> sparse
     Matrix(0, 3, 2, sparse=FALSE)# forced 'dense'
     Matrix(1:6, 3, 2)           # a 3 by 2 matrix
     Matrix(1:6, nrow=3)
     Matrix(1:6, ncol=2)

     ## logical ones:
     Matrix(diag(4) >  0)# -> "ldiMatrix" with diag = "U"
     Matrix(diag(4) >= 0)# -> "lsyMatrix"
     l3 <- upper.tri(matrix(,3,3))
     Matrix(l3)  # -> "ltCMatrix"
     Matrix(! l3)# -> "ltrMatrix"

     Matrix(1:9, nrow=3,
            dimnames = list(c("a", "b", "c"), c("A", "B", "C")))
     (I3 <- Matrix(diag(3)))# identity, i.e., unit "diagonalMatrix"
     str(I3) # note the empty 'x' slot

     (A <- cbind(a=c(2,1), b=1:2))# symmetric *apart* from dimnames
     Matrix(A)                    # hence 'dgeMatrix'
     (As <- Matrix(A, dimnames = list(NULL,NULL)))# -> symmetric
     stopifnot(is(As, "symmetricMatrix"))

