Skip to content

diag(x, n) not preserving integer and logical x

1 message · Radford Neal

#
Martin Maechler wrote:

        
Duncan Murdoch wrote:
Making diag(1:10) return an integer matrix does make sense, but it
could still be undesirable.  Often, the user will have intended to
get a real matrix, and will after another operation, but only after an
unnecessary coercion is done. For example: x<-diag(1:10); x[1,2]<-2.0

I personally think keeping diag(1:10) integer is best, but I thought 
I'd point out the contrary argument.

Having diag(rep(TRUE,10)) return a logical matrix with FALSE off the
diagonal does not strike me as too odd.  It makes sense if you think
of (FALSE, TRUE) as forming a field under operations of sum=XOR and
product=AND.  And of course it will typically be converted to a 0/1
matrix later if that's what was actually intended.

   Radford Neal