Skip to main content

2.5) Classes of Data Vectors (cont'd)


Classes for more complex objects include "formula", "list", "data.frame", "array", and "matrix". Sometimes one class can be coerced to behave as another (see the exercise below), but otherwise you may get an error (perhaps mentioning "unable to coerce..." or "incorrect number of dimensions"). You can sometimes get round this by using functions that begin as., like as.matrix() to turn a data frame into a matrix or as.numeric() to turn any structured object into a simple vector of numbers.

A column of a data frame (or an element of any ‘list’ object) can be specified by appending its name to the data frame name with a dollar sign, e.g.: GRASS$Tlrs. This is an example of dissecting an object to get at one of its component parts.

Find the means of the numeric columns in GRASS and store them together as a new vector called GRASS.means.