home *** CD-ROM | disk | FTP | other *** search
-
- _E_x_t_r_a_c_t _o_r _R_e_p_l_a_c_e _p_a_r_t_s _o_f _a_n _O_b_j_e_c_t
-
- x[i]
- x[i,j, ...]
- x[i,j, ..., drop=T]
- x[[i]]
- x[[i,j, ...]]
- x$name
-
- _D_e_s_c_r_i_p_t_i_o_n:
-
- These operators act on vectors, matrices, dataframes
- and lists. If one of these expressions is on the left
- hand side of an assignment then that part of x is set
- to the value of the right hand side of the assignment.
-
- These operators are generic. You can write methods to
- handle subsetting of specific classes of data.
-
- The [[ operator requires all relavent subscripts be
- supplied. With the [ operator a comma separated blank
- indicates that all entries in that dimension are
- selected.
-
- When operating on a list the [[ operator gives the
- specified element of the list while the [ operator
- returns a list with the specified element(s) in it.
-
- _E_x_a_m_p_l_e_s:
-
- x <- 1:12; m <- matrix(1:6,nr=2); li <- list(pi=pi, e = exp(1))
- x[10] # the tenth element of x
- m[1,] # the first row of m (which must be a matrix)
- li[[1]] # the first element of list li
- y<-list(1,2,a=4,5)
- y[c(3,4)] # a list containing the third and fourth elements of y
- y$a #the element of y named a
-
-