I have a data.table with, say, five rows
d <- data.table(rnorm(5),rnorm(5),rnorm(5))
which I can convert to a matrix and remove the first column,
m <- as.matrix(d)[,-1]
and then index using m[cbind(r,c)]
where r
and c
change at each iteration.
I noticed that when d
has only one row and I convert it,
d <- data.table(rnorm(1),rnorm(1),rnorm(1))
m <- as.matrix(d)[,-1]
m
is of class numeric
and indexing m[cbind(1,r)]
no longer works. This appears to be due to the [,-1]
, otherwise m
is of class matrix
and indexing works just fine.
Does anyone know where this discontinuity comes from and whether there is a different way of removing the first column that does not cause this problem?