mode
Data Mode of the Values in a Vector

Description

Returns or changes the type of the object.

Usage

mode(x)
mode(x) <- value
storage.mode(x)
storage.mode(x) <- value

Arguments

x any object. Missing values (NAs) are allowed.
value a character string specifying the new mode.

Details

When you use mode on the left of an assignment, it calls the corresponding as.xxx function (where xxx is the mode string value) to do the conversion. This design allows mode to handle user-defined conversions. (storage.mode handles only built-in conversions.)
storage.mode is relevant when you are calling .Fortran or .C with numeric data. It coerces the data as either "integer" or "double". To pass data as single-precision floating point numbers, you must use the as.single function, or you must set mode to "single".
The atomic modes are: The other modes include: Other modes are used internally, so you rarely encounter them.
Value
storage.mode returns a character string that is the type of x. (Similar to typeof.)
mode returns a character string similar to that of storage.mode.
Note that vectors with the storage.mode "double" or "integer" are reported to be of mode "numeric".
Side Effects
When you use mode on the left of an assignment, the mode of the object is changed to value, interpreted as a character string.
The attributes of x are unchanged.
Note
The mode function has nothing to do with the statistical concept of the mode of a distribution.
See Also
typeof, class, .Fortran, as.single, double, integer, vector, complex, character, numeric, is.atomic.
Examples
x <- 42
mode(x)  # "numeric"
storage.mode(x)  # "double"
mode(x) <- "complex"  # change mode to complex
storage.mode(x) <- "double"

# User-defined conversion as.foo <- function(x) class(x) <- 'foo' x <- 'bar' mode(x) <- 'foo' # calls as.foo

Package base version 6.1.4-13
Package Index