Skip to content

data.matrix returns mode logical for zero rows (PR#8496)

1 message · Brian Ripley

#
On Tue, 17 Jan 2006 jonathan.swinton at astrazeneca.com wrote:

            
You don't show us an example of a data frame with zero rows, nor do you 
show an example of data.matrix returning logical, so this report was very 
confusing.  Please do give a reproducible example as the posting guide and 
FAQ ask.

df[FALSE,] is not a data frame, so I don't know why you expect data.matrix 
to be applicable (it is the same as as.matrix in such cases).

Here is an actual reproducible example:

DF <- data.frame(x=c("a", "b"), y=2:3)[FALSE,]
typeof(data.matrix(DF))
No, but there is a bug in your description as you are describing 
replacement indexing, not `assertion'.  Coercion in replacement indexing 
is done to accommodate the new values, and there are none in your example.
(That is how S has always done it in my experience, although the Blue 
Book p.359 says otherwise.)

If you want to assert that an object be numeric, use mode(x) <- "numeric".