kyousan at sina.com
2007-Jun-20 02:26 UTC
[Rd] Error in funcion distancia() in package dprep(v1.0) (PR#9745)
Full_Name: Kang Yousan Version: 2.5.0 OS: Windows XP Submission from: (NULL) (211.137.211.67) There is a bug in function distancia() in package dprep. See the description below.> distancia1 function (x, y) 2 { 3 if (class(y) == "matrix") { 4 distancia = drop(sqrt(colSums((x - t(y))^2))) 5 distancia = t(distancia) 6 } 7 else distancia = sqrt(sum((x - y)^2)) 8 distancia 9 } The t(y) in line 4 should be modified to y. Before the change, see example:> (x=rnorm(4))[1] 0.02670846 1.24512505 -0.22145290 1.99760521> (y=matrix(rnorm(12),4,3))[,1] [,2] [,3] [1,] 0.4181184 1.8980350 -1.7398861 [2,] -0.1906483 -0.1777747 0.6666913 [3,] 0.2239468 -0.2631944 -0.3586917 [4,] -1.0316230 -0.7121346 0.3587542> distancia(x,y)[,1] [,2] [,3] [,4] [1,] 1.698568 2.272631 2.336264 2.847838 After the change: a<-function (x, y) { if (class(y) == "matrix") { distancia = drop(sqrt(colSums((x - y)^2))) distancia = t(distancia) } else distancia = sqrt(sum((x - y)^2)) distancia }> a(x,y)[,1] [,2] [,3] [1,] 3.404299 3.587609 2.481957 The latter result is resonable according to the description of the function return value: "distancia numeric value representing the Euclidean distance between x and y, or a row matrix representing the Euclidean distance between x and each column of y." Thanks for attention.
Peter Dalgaard
2007-Jun-20 13:47 UTC
[Rd] Error in funcion distancia() in package dprep(v1.0) (PR#9745)
kyousan at sina.com wrote:> Full_Name: Kang Yousan > Version: 2.5.0 > OS: Windows XP > Submission from: (NULL) (211.137.211.67) > > > There is a bug in function distancia() in package dprep. See the description > below. >http://cran.r-project.org/doc/FAQ/R-FAQ.html#R-Bugs : Finally, check carefully whether the bug is with R, or a contributed package. Bug reports on contributed packages should be sent first to the package maintainer, and only submitted to the R-bugs repository by package maintainers, mentioning the package in the subject line. -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907