[<--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")

