Skip to main content

1.5) Types of Objects


Now we need to think about the R language for a moment. The R language is object-oriented, and everything in R can be seen as an object with its own properties.

The most common kinds of objects are probably functions and vectors. If you know some biology, you could think of these as enzymes and simple polypeptides: functions are complex objects that do something, while vectors are simply strings of numbers or words, etc (data). R works by applying function objects to data objects. Normally you must name data objects (although there are some pre-defined vectors, like pi and Inf), whereas most functions that you will need are already defined. So our object P (above) was just a single-element vector; to make a vector with multiple elements, we must use the function c() – which we will meet very soon.

E. Every object automatically has a class and a mode; these can be the same...

# Exploring modes and classes:
class(2)
mode(2)
class(pi)
class(class)
mode(class) # etc...

but classes can be used to specify additional properties to ensure that objects are treated in appropriate ways by certain functions. This is one thing that makes R very user-friendly and versatile – you don’t need to know how everything works in order to program in R, because there are intuitive methods for handling different kinds of objects.