Replacement values of a dist object with either ij or position indexing
dist_replace(object, i, j, value, k)
object | dist object |
---|---|
i | (integer vector) row positions |
j | (integer vector) column positions |
value | (integer/numeric vector) Values to replace |
k | (integer vector) positions |
dist object
There are two modes to specify the positions:
ij-mode where i and j are specified and k is missing. If i or j are missing, they are interpreted as all values of i or j (similar to matrix or dataframe subsetting). Lengths of i, j are required to be same. If 'value' is singleton, then it is extended to the length of i or j. Else, 'value' should have same length as i or j.
k-mode where k is present and both i and k are missing. k is the positions in the dist object. If 'value' is singleton, then it is extended to the length of k. Else, 'value' should have same length as k.
# create a dist object d <- dist(iris[,1:4]) attr(d, "Labels") <- outer(letters, letters, paste0)[1:150] head(d)#> [1] 0.5385165 0.5099020 0.6480741 0.1414214 0.6164414 0.5196152max(d)#> [1] 7.085196#> aa ba ca da ea #> aa 0.0000000 0.5385165 0.509902 0.6480741 0.1414214 #> ba 0.5385165 0.0000000 0.300000 0.3316625 0.6082763 #> ca 0.5099020 0.3000000 0.000000 0.2449490 0.5099020 #> da 0.6480741 0.3316625 0.244949 0.0000000 0.6480741 #> ea 0.1414214 0.6082763 0.509902 0.6480741 0.0000000#> [1] 100#> [1] 102#> [1] 11 12 13 14 15d <- dist_replace(d, c("ca", "da"), c("aa", "ba"), 102) dist_extract(d, c("ca", "da"), c("aa", "ba"), product = "inner")#> [1] 102 102#> [1] 101#> [1] 101