Name | extract |
||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
These operators are generic. You can write methods to handle indexing of specific classes of objects, see InternalMethods as well as [.data.frame and [.factor. The descriptions here apply only to the default methods. Note that separate methods are required for the replacement functions [<-, [[<- and $<- for use when indexing occurs on the assignment side of an expression. The most important distinction between [, [[ and $ is that the [ can select more than one element whereas the other two select a single element. The default methods work somewhat differently for atomic vectors, matrices/arrays and for recursive (list-like, see is.recursive) objects. $ is only valid for recursive objects, and is only discussed in the section below on recursive objects. Subsetting (except by an empty index) will drop all attributes except names, dim and dimnames. Indexing can occur on the right-hand-side of an expression for extraction, or on the left-hand-side for replacement. When an index expression appears on the left side of an assignment (known as subassignment) then that part of x is set to the value of the right hand side of the assignment. In this case no partial matching of character indices is done, and the left-hand-side is coerced as needed to accept the values. For vectors, the answer will be of the higher of the types of x and value in the hierarchy raw < logical < integer < double < complex < character < list < expression. Attributes are preserved (although names, dim and dimnames will be adjusted suitably). Subassignment is done sequentially, so if an index is specified more than once the latest assigned value for an index will result. It is an error to apply any of these operators to an object which is not subsettable (e.g., a function). |
||||||||||||||
Syntax | x[i] x[i, j, ... , drop = TRUE] x[[i, exact = TRUE]] x[[i, j, ..., exact = TRUE]] x$name getElement(object, name) x[i] <- value x[i, j, ...] <- value x[[i]] <- value x$name <- value | ||||||||||||||
Parameters |
|
Cover
Reference
Tutorials
Bugs