Object-Oriented Programming with S3 and R6 in R
Richie Cotton
Data Evangelist at DataCamp
str(sleep)
'data.frame': 20 obs. of 3 variables:
$ extra: num 0.7 -1.6 -0.2 -1.2 -0.1 ...
$ group: Factor w/ 2 levels "1","2": 1 1 1 1 1 ...
$ ID : Factor w/ 10 levels "1","2","3","4",..: 1 2..
class(sleep)
"data.frame"
(int_mat <- matrix(1:12, 3))
[,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12
class(int_mat)
"matrix"
typeof(int_mat)
"integer"
(num_mat <- matrix(rnorm(12), 3))
[,1] [,2] [,3] [,4]
[1,] -0.2911535 -0.1139933 -0.71290868 0.8640191
[2,] -2.2266419 -1.3604316 -1.90716974 0.4012884
[3,] -0.7504663 -1.2478873 0.01104117 -0.8127333
class(num_mat)
"matrix"
typeof(num_mat)
"double"
class()
is your first choice for determining the kind of variabletypeof()
is also occasionally usefulmode()
and storage.mode()
are old functions; don't use themObject-Oriented Programming with S3 and R6 in R