typeof
The Type of an Object
typeof
determines the (R internal)
type or storage mode of any object
- Keywords
- attribute
Usage
typeof(x)
Arguments
- x
- any R object.
Value
-
A character string. The possible values are listed in the structure
TypeTable
in src/main/util.c. Current values are
the vector types "logical"
, "integer"
, "double"
,
"complex"
, "character"
, "raw"
and "list"
,
"NULL"
,
"closure"
(function), "special"
and "builtin"
(basic functions and operators), "environment"
, "S4"
(some S4 objects) and others that are unlikely to be seen at user
level ("symbol"
, "pairlist"
, "promise"
,
"language"
, "char"
, "..."
, "any"
,
"expression"
, "externalptr"
, "bytecode"
and
"weakref"
).
See Also
isS4
to determine if an object has an S4 class.
Examples
library(base)
typeof(2)
mode(2)
Community examples
[Basic data types](https://www.p-wert.eu/rref/einfache-datentypen/) A comparison of type, mode, storage mode and class.. ```r values <- list(TRUE, 5L, 5.3, 3i, "string", raw(2)) values_string <- as.character(values) types <- c() modes <- c() storage_modes <- c() classes <- c() for (variable in values) { types <- append(types, typeof(variable)) modes <- append(modes, mode(variable)) storage_modes <- append(storage_modes, storage.mode(variable)) classes <- append(classes, class(variable)) } result <- data.frame(values_string, types, modes, storage_modes, classes) print(result) ```
```r typeof(c(1,2,3)) typeof(c(1,2,3, "a")) ```