Some corrections on the lecture
This commit is contained in:
16
R/norme.R
Normal file
16
R/norme.R
Normal file
@@ -0,0 +1,16 @@
|
||||
#' @export
|
||||
norm <- function(data,l=2) {
|
||||
no <- function(x,y) sum(abs(data[x,]-data[y,])^l)^(1/l)
|
||||
n = nrow(data)
|
||||
d = matrix(0,nrow = n,ncol = n)
|
||||
for (i in 1:n)
|
||||
for (j in i:n) {
|
||||
d[i,j] <- no(i,j)
|
||||
d[j,i] <- d[i,j]
|
||||
}
|
||||
|
||||
rownames(d) = rownames(data)
|
||||
colnames(d) = rownames(data)
|
||||
|
||||
as.dist(d)
|
||||
}
|
||||
Reference in New Issue
Block a user