cor
tests whether x
or y
(arguments) are data.frames
(using is.data.frame
- which data.table will return TRUE as well) and then coerces the argument to a matrix
if (is.data.frame(x)) x <- as.matrix(x)
The issue appears to be the different ways as.matrix.data.table
and as.matrix.data.frame
work with the example matrix
as.matrix(dt)
returns a character matrix - this would appear to be a bug in data.table
as.matrix.data.table
and as.matrix.data.frame
appear to share similar code for coercing that is dispatching differently
# data.table:::as.matrix.data.table
else if (non.numeric) {
for (j in seq_len(p)) {
if (is.character(X[[j]]))
next
xj <- X[[j]]
miss <- is.na(xj)
xj <- if (length(levels(xj)))
as.vector(xj)
else format(xj)
is.na(xj) <- miss
X[[j]] <- xj
}
}
## base::as.matrix.data.frame
else if (non.numeric) {
for (j in pseq) {
if (is.character(X[[j]]))
next
xj <- X[[j]]
miss <- is.na(xj)
xj <- if (length(levels(xj)))
as.vector(xj)
else format(xj)
is.na(xj) <- miss
X[[j]] <- xj
}
}
Currently the data.table
version coerces the logical column to a character.