Skip to content
Prev 366150 / 398502 Next

Infelicity in print output with matrix indexing of `[.data.frame`

I have no argument with the premise that an atomic vector must be of a single mode.  But the exact same values were established with a numeric vector into those positions indexed by the 2-column matrix. Why does extraction need to coerce the entire dataframe to matrix when none of the extracted values are character? I suppose my request is that the very simple line in `[.data.frame`


    if (is.matrix(i)) 
            return(as.matrix(x)[i])

If it were replaced by code that would only extract from the values needed and then use a shifted version of the selection matrix, you could get values that were not coerced by being innocent bystanders of a dataframe colum that was not relevant.

as.matrix( x[ min( i[ , 1]):max( i[ , 1]), min( i[ ,2 ]):max(i[ , 2]) ])[
                   cbind( i[,1]-min( i[ , 1]) +1, i[,2]- min( i[ ,2 ]) +1) ]