dist(x, method = "euclidean", diag = FALSE, upper = FALSE, p = 2)# Generic function as.dist(m, diag = FALSE, upper = FALSE) ## Default S3 method: as.dist(m, diag = FALSE, upper = FALSE)
## S3 method for class 'dist': as.matrix(x, ...) ## S3 method for class 'dist': labels(object, ...) ## S3 method for class 'dist': print(x, diag = NULL, upper = NULL, digits = getOption("digits"), justify = "none", right = TRUE, ...)
x | a matrix (typically a data matrix). The distances computed are among the rows of x. Missing values (NAs) are allowed. | ||
method |
a character string that specifies the distance method to use. You can
type one of the following:
The rule is similar for the "manhattan" metric, except that the coefficient is ncol(x)/ng. The "binary" metric excludes columns in which either row has an NA. If all values for a particular distance are excluded, the distance is NA. | ||
diag | a logical value that specifies to print the diagonal of the distance matrix. If TRUE, the diagonal is printed. | ||
upper | a logical value that specifies to print the upper triangular of the distance matrix. If TRUE, the upper triangular is printed. | ||
p | a positive real number that specifies the power number to use in the "minkowski" method. The default is 2. | ||
m | an object of class "dist", an object that inherits from class "dist", or an object that can be coerced to a matrix through the as.matrix function. The m object is normally a numeric square matrix. | ||
x, object | an object of class "dist" or an object that inherits from class "dist". | ||
digits | a numeric value that specifies the number of significant digits that should be printed in numeric or complex data. By default, the value is configured through the "digits" argument in the options function. | ||
justify | a character string that specifies the justification of character strings relative to each other. You can choose "none", "left", "right", or "centre". For more information, see format. | ||
right | a logical value that controls alignment of character strings. If TRUE (the default), output is right aligned. | ||
... | other optional arguments to be passed to or from methods. |
nrow(x) * (i - 1) - i * (i - 1) / 2 + (j - i) of the result |
"Size" | displays the number of objects, that is, nrow(x). |
"Labels" | the row names of x or m (if they exist), otherwise column names of m (if they exist). |
"Diag" | the value of argument diag. |
"Upper" | the value of argument upper. |
"method" | the value of the distance method specified in method. |
"p" | the value of argument p only returned if you specified a value in the "minkowski" method. |
"call" | the call to create this "dist" object. |
as.matrix.dist | returns a square distance matrix with row names and column names. |
format.dist | coerces the distance vector to character strings using a specified format. |
labels.dist | returns the "Labels" attribute of a dist object. |
print.dist | only prints out a dist object in distance matrix format. |
# create a sample object x <- Sdatasets::votes.repub[13:23, 1:8] dist(x, "max") # distances among rows by maximum dist(t(x)) # distances among cols in Euclidean metric dist(x, "canberra", diag = TRUE) ret <- dist(x, "minkowski", upper = TRUE, p = 3) attributes(ret) print(ret) as.matrix(ret) format(ret, digits = 3) labels(ret)as.dist(matrix(1:9, nrow = 3, dimnames = list(paste("R",1:3, sep = "_"), paste("C", 1:3, sep = "_"))), diag = TRUE, upper = TRUE) ## R_1 R_2 R_3 ## R_1 0 2 3 ## R_2 2 0 6 ## R_3 3 6 0