Skip to content
Prev 79319 / 398502 Next

diag() problem

On 10/19/2005 10:55 AM, Robin Hankin wrote:
It's trying to check whether the row names match the column names, in 
which case it will assign those names to the diagonal elements.  But the 
writer didn't figure someone would have NA names, so the test

all((nm <- nms[[1]][1:m]) == nms[[2]][1:m])

fails.

It could be "fixed" by putting "na.rm=TRUE" into the all(), but that's 
probably not right:

 > all(c(1, NA) == c(1, 2), na.rm = TRUE)
[1] TRUE

I think we want to wrap the values in "paste", to convert to non-missing 
characters.  That would be

all(paste((nm <- nms[[1]][1:m])) == paste(nms[[2]][1:m]))

and would give

 > diag(u)
  constant      <NA>      <NA>      <NA>
  5.423347  3.227376 11.948892 10.098983

Any objections to me committing this change?

Duncan Murdoch