Working with the S3 object system
The S3 object system in R is a simple, loose, object-oriented system. Every basic object type has an S3 class name. For example, integer
, numeric
, character
, logical
, list
,
data.frame
, and so on are all S3 classes.
For example, the type of vec1
class is double
, which means the internal type or storage mode of vec1
is double floating numbers. However, its S3 class is numeric
:
vec1 <- c(1, 2, 3) typeof(vec1) ## [1] "double" class(vec1) ## [1] "numeric"
The type of data1
class is list
, which means the internal type or storage mode of data1
is a list, but its S3 class is data.frame
:
data1 <- data.frame(x = 1:3, y = rnorm(3)) typeof(data1) ## [1] "list" class(data1) ## [1] "data.frame"
In the following sections, we'll ...
Get Learning R Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.