My research so far
Most articles discuss the difference between class
and typeof
but I haven't found much to the differences between mode
, storage.mode
, and typeof
.
I get that mode
, storage.mode
, and typeof
are more similar and class
is more different. I get that the former two call typeof
and I understand that they handle specific types slightly differently (I even know which ones and how). What I would like to know is what the idea behind that is.
Minimal working example
library(data.table)
my_vector_boolean <- c(TRUE, FALSE, T, F)
my_vector_integer <- c(1L, 2L, 3L)
my_vector_character <- c("a", "b", "abc")
my_vector_factor <- as.factor(c("a", "b", "c"))
my_list <- list(a=1, b=2L, c="c")
my_matrix <- matrix(c(1,2,3, 11,12,13), nrow = 2, ncol = 3, byrow = TRUE,
dimnames = list(c("row1", "row2"), c("col1", "col2", "col3")))
my_dataframe <- data.frame(1, 1L:10L, sample(3, 10, replace = TRUE))
my_datatable <- data.table(1, 1L:10L, sample(3, 10, replace = TRUE))
datatypeslist <- list(
my_vector_boolean = my_vector_boolean,
my_vector_integer = my_vector_integer,
my_vector_character = my_vector_character,
my_vector_factor = my_vector_factor,
my_list = my_list,
my_matrix = my_matrix,
my_dataframe = my_dataframe,
my_datatable = my_datatable
)
multi.sapply <- function(...) {
arglist <- match.call(expand.dots = FALSE)$...
var.names <- sapply(arglist, deparse)
has.name <- (names(arglist) != "")
var.names[has.name] <- names(arglist)[has.name]
arglist <- lapply(arglist, eval.parent, n = 2)
x <- arglist[[1]]
arglist[[1]] <- NULL
result <- sapply(arglist, function (FUN, x) sapply(x, FUN), x)
colnames(result) <- var.names[-1]
return(result)
}
multi.sapply(datatypeslist, typeof, storage.mode, mode, class)
What I am looking for
What kind of answer I am not looking for: "mode
and storage.mode
handle single
differently.
What kind of answer I am loking for: "typeof
is the data type that is used in the underlying C implementation, while mode
is the data type that ... and storage.mode
is the data type that ..."
Additionally I would appreciate a differentiation of the terms "mode" and "type" that have been used in manuals and tutorials. For example it has been said that typeof
return the mode of a data object - which seems confusing to me.
I hope that question was specific/clear enough. Please tell me what was not clear, before down-voting or voting for closing.