-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
distance
with as.dist.obj=TRUE
does not work correctly when the input data has 2 rows
#29
Comments
Possible solution is to slightly modify the Line 968 in c15b781
if (as.dist.obj) {
if (ncols == 2) {
dist <- stats::as.dist(matrix(c(0, dp1, dp1, 0), nrow = 2), diag = diag, upper = upper)
} else {
dist <- stats::as.dist(dist, diag = diag, upper = upper)
}
attr(dist, "method") <- method
return(dist)
} |
Hi Jakub, This is a fantastic suggestion! Thank you very much for catching this! I now added your suggestions and please feel free to test whether it is sufficient. library(philentropy)
m1 = matrix(c(1, 2), ncol = 1)
m2 = matrix(c(1, 2, 3), ncol = 1)
dist(m1)
#> 1
#> 2 1
distance(m1, as.dist.obj = TRUE)
#> Metric: 'euclidean'; comparing: 2 vectors.
#> 1
#> 2 1
dist(m2)
#> 1 2
#> 2 1
#> 3 2 1
distance(m2, as.dist.obj = TRUE)
#> Metric: 'euclidean'; comparing: 3 vectors.
#> v1 v2
#> v2 1
#> v3 2 1 P.S. Sorry for the delay on your your pull request, I am a bit delayed, but I am working on it! |
Thanks! PS No problem - I can wait. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the case of an input object with 2 rows, the R
dist()
function returns an output of length 1 (a distance between the first and the second row). However, thedistance()
function withas.dist.obj=TRUE
returns an empty object in these case:Created on 2021-07-29 by the reprex package (v2.0.0)
The text was updated successfully, but these errors were encountered: