wolbers@stat.math.ethz.ch
2001-Jun-01 11:47 UTC
[Rd] v matrix of svd(X) loses dimensions if nrow(X)==1 (PR#963)
Dear R-developers I'm not very sure whether this is really a bug and not a feature:> is.matrix(svd(matrix(1:12,nrow=1))$v)[1] FALSE In all other cases the $v component is a matrix. Also, the $u component always seems to be a matrix as indicated in the doc. My R-version:> version_ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 1 minor 2.3 year 2001 month 04 day 26 language R Yours Marcel Wolbers PS: - On S-Plus Version 5.1 Release 1 for Linux 2.0.31 : 1999 > is.matrix(svd(matrix(1:12,nrow=1))$v) [1] T - Thanks a lot for the great piece of software you've written -- Marcel Wolbers, LEO C14, Seminar for Statistics, ETH Zurich CH-8092 Zurich, Switzerland; phone: (01) 632 2252 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Martin Maechler
2001-Jun-01 12:39 UTC
[Rd] v matrix of svd(X) loses dimensions if nrow(X)==1 (PR#963)
Marcel> Dear R-developers
Marcel> I'm not very sure whether this is really a bug and not a
feature:
Marcel> is.matrix(svd(matrix(1:12,nrow=1))$v)
Marcel> [1] FALSE
Marcel> In all other cases the $v component is a matrix. Also, the $u
Marcel> component always seems to be a matrix as indicated in the doc.
It's the famous `programmer bug' of not using `` , drop = FALSE
''
when matrix subscripting in functions....
in the 2nd-to-last line of svd() :
if(nv && nv < p) z$v <- z$v[, 1:nv, drop = FALSE]
^^^^^^^^^^^^^^
add this.
{merci, Marcel!}
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._