Statistical Analysis: an Introduction using R/R/Accessing elements of vectors

It is common to want to access certain elements of a vector: for example, we might want to use only the 10th element, or the first 4 elements, or select elements depending on their value. The way to do this is to take the vector and prepend the indexing operator, (i.e. square brackets). If these square brackets contain The use of logical vectors may seem a little complicated. However, they can be extremely useful, because they are the key behind using comparison operators. These can be used, for example, to identify which US states are small, with an area less than (<) 10 000 square miles (as demonstrated below).
 * A positive number or numbers, then this has the effect of picking those particular elements of the vector
 * A negative number or numbers, then this has the effect of picking the whole vector except those elements
 * A logical vector, then each element of the logical vector indicates whether to pick (if TRUE) or not (if FALSE) the equivalent element of the original vector.