> observations[3] [1] 1 > observations[5:7] [1] 5.9 4.0 6.7 > observations[c(1,2,7,1)] [1] 2.0 4.6 6.7 2.0The above functions return the third observation, the fifth through seventh observations, and the first, second, seventh and first (again) observations, respectively.
To select everything except some particular element or set of elements, use a minus sign. The following command would return the entire vector except the first element.
> observations[-1] [1] 4.6 1.0 3.7 5.9 4.0 6.7 2.8 1.4 3.1Vectors can also be searched using logic statements. To pick out all observations which have a value larger than four, type:
> observations[observations>4] [1] 4.6 5.9 6.7