diag() losing dimnames
Peter Dalgaard BSA
p.dalgaard@biostat.ku.dk
09 Sep 1998 18:35:34 +0200
Martin Maechler <maechler@stat.math.ethz.ch> writes:
> --- ../R-0.62.3/src/library/base/R/diag.R Fri Mar 6 08:37:13 1998
> +++ diag.R Wed Sep 9 17:58:11 1998
> @@ -2,7 +2,7 @@
> function(x = 1, nrow, ncol = n)
> {
> if(is.matrix(x) && nargs() == 1)
> - return(as.matrix(x)[1 + 0:(min(dim(x)) - 1) * (dim(x)[1] + 1)])
> + return(c(x)[1 + 0:(min(dim(x)) - 1) * (dim(x)[1] + 1)])
> if(missing(x))
> n <- nrow
> else if(length(x) == 1 && missing(nrow) && missing(ncol)) {
That's only half a solution:
> m[1:4]
1 2 NA NA
1 2 3 4
Splus:
> m<-matrix(1:4,2)
> dimnames(m)<-list(1:2,NULL)
> m
[,1] [,2]
1 1 3
2 2 4
> m[1:4]
[1] 1 2 3 4
R
> m<-matrix(1:4,2)
> rownames(m)<-1:2
> m[1:4]
1 2 NA NA
1 2 3 4
I.e. it seems that it should be fixed in the "[" internals.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._