[<--methods              package:Matrix              R Documentation

_M_e_t_h_o_d_s _f_o_r "[<-" - _A_s_s_i_g_n_i_n_g _t_o _S_u_b_s_e_t_s _f_o_r '_M_a_t_r_i_x'

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

     Methods for '"[<-"', i.e., extraction or subsetting mostly of
     matrices, in package 'Matrix'.

_M_e_t_h_o_d_s:

     There are more than these:

     _x = "_M_a_t_r_i_x", _i = "_m_i_s_s_i_n_g", _j = "_m_i_s_s_i_n_g", _v_a_l_u_e= "_A_N_Y" is
          currently a simple fallback method implementation which
          ensures readable error messages.

     _x = "_M_a_t_r_i_x", _i = "_A_N_Y", _j = "_A_N_Y", _v_a_l_u_e= "_A_N_Y" currently gives
          an error 

     _x = "_d_e_n_s_e_M_a_t_r_i_x", _i = "_i_n_d_e_x", _j = "_m_i_s_s_i_n_g", _v_a_l_u_e= "_n_u_m_e_r_i_c" 
          ... 

     _x = "_d_e_n_s_e_M_a_t_r_i_x", _i = "_i_n_d_e_x", _j = "_i_n_d_e_x", _v_a_l_u_e= "_n_u_m_e_r_i_c" ... 

     _x = "_d_e_n_s_e_M_a_t_r_i_x", _i = "_m_i_s_s_i_n_g", _j = "_i_n_d_e_x", _v_a_l_u_e= "_n_u_m_e_r_i_c" 
          ... 

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

     '[-methods' for subsetting '"Matrix"' objects; the 'index' class;
     'Extract' about the standard subset assignment (and extraction).

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

     set.seed(101)
     (a <- m <- Matrix(round(rnorm(7*4),2), nrow = 7))

     a[] <- 2.2 # <<- replaces **every** entry
     a
     ## as do these:
     a[,] <- 3 ; a[TRUE,] <- 4

     m[2, 3]  <- 3.14 # simple number
     m[3, 3:4]<- 3:4  # simple numeric of length 2

     ## sub matrix assignment:
     m[-(4:7), 3:4] <- cbind(1,2:4) #-> upper right corner of 'm'
     m[3:5, 2:3] <- 0
     m[6:7, 1:2] <- Diagonal(2)
     m

     ## rows or columns only:
     m[1,] <- 10
     m[,2] <- 1:7
     m[-(1:6), ] <- 3:0 # not the first 6 rows, i.e. only the 7th
     as(m, "sparseMatrix")

