Desktop Survival Guide
by Graham Williams

Rows and Columns

A number of operators are available to extract data from matrices. The single open square bracket [ is used to one or more elements from a matrix, while the double open square bracket returns just the specific element specified, requiring all relevant subscripts to be supplied.

> ds[1:20,]		        # Rows 1 to 20.
> ds[,5:10]      		# Columns 5 to 10. 
> ds[,c(3,5,8,9)]		# Columns 3, 5, 8, and 9.
> lst[[1]]                      # First element of list lst.

The [ operator can select multiple elements from an object whilst double square backets and $ select just a single element.

Copyright © Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010