R - Class

> Procedural Languages > R

1 - About

A class is just an attribute of an object. You can remove the attribute with the function unclass. The class with then become the type

A list can have different class.

Advertising

3 - Management

3.1 - Unclass

unclass returns (a copy of) its argument with its class attribute removed. (It is not allowed for objects which cannot be copied, namely environments and external pointers.)

Example: A data frame will return a list:

class(USArrests)
[1] "data.frame"

If you unclass it, you will get a list

class(unclass(USArrests))
[1] "list"

3.2 - Change

Objects can change of class (coercion) using the as.* functions (if available).

4 - Type

4.1 - Atomic

Advertising

4.2 - Non Atomic

5 - Hierarchy

The following hierarchy (order of precedence) occurs when creating an object with several classes:

  1. NULL
  2. raw
  3. Numeric (double)
  4. expression
  5. function

? And:

Advertising

6 - Example

6.1 - List

See R - List

6.2 - Function

R - Function

class(mean)
[1] "function"
> class(plot)
[1] "function"
lang/r/class.txt · Last modified: 2017/02/12 21:02 by gerardnico