Rev 14506 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{Extract}\title{Extract or Replace Parts of an Object}\alias{Extract}\alias{Subscript}\alias{[}\alias{[[}\alias{$}\alias{[<-}\alias{[[<-}\alias{$<-}%- methods\alias{[.data.frame}\alias{[[.data.frame}\alias{[<-.data.frame}\alias{[[<-.data.frame}\alias{[.factor}\alias{[.formula}\alias{[.ts}\alias{[<-.factor}\alias{[.noquote}\alias{[<-.noquote}\description{Operators act on vectors, arrays, dataframes and lists to extract orreplace subsets.}\usage{x[i]x[i, j, \dots]x[i, j, \dots , drop=TRUE]x[[i]]x[[i, j, \dots]]x$name}\arguments{\item{i,j,name}{elements to extract or replace}\item{drop}{For data frames, matrices, and arrays. If \code{TRUE} theresult is coerced to the lowest possible dimension (see examplesbelow).}}\details{If one of these expressions appears on the left side of an assignmentthen that part of \code{x} is set to the value of the right hand sideof the assignment.These operators are generic. You can write methods to handle subsettingof specific classes of data.The \code{[[} operator requires all relevant subscripts be supplied.With the \code{[} operator a comma separated blank indicates that allentries in that dimension are selected.When \code{[.data.frame} is used for subsetting rows of a\code{\link{data.frame}}, it returns a dataframe with unique row names,using \code{\link{make.names}( * , unique = TRUE)}, see the \code{swiss}example below.When operating on a list, the \code{[[} operator gives the specifiedelement of the list while the \code{[} operator returns a list withthe specified element(s) in it.The operators \code{$} and \code{$<-} do not evaluate their secondargument. It is translated to a string and that string is used tolocate the correct component of the first argument.}\seealso{\code{\link{list}}, \code{\link{array}}, \code{\link{matrix}}.}\examples{x <- 1:12; m <- matrix(1:6,nr=2); li <- list(pi=pi, e = exp(1))x[10] # the tenth element of xm[1,] # the first row of matrix mm[1, , drop = FALSE] # is a 1-row matrixli[[1]] # the first element of list liy <- list(1,2,a=4,5)y[c(3,4)] # a list containing elements 3 and 4 of yy$a # the element of y named adata(swiss)swiss[ c(1, 1:2), ] # duplicate row, unique row names}\keyword{array}\keyword{list}