search for: calcnorm2

Displaying 1 result from an estimated 1 matches for "calcnorm2".

Did you mean: calcnorm
2013 Mar 10
2
list + lapply insead of matrix + apply
...2) for list form example, the conversion is x.list <- lapply(seq_len(nrow(x)), function(i) x[i,]) ### list version calcnorm=function(a, b){ diff <- mapply("-", a, b) diff2 <- mapply("*", diff, diff) sqrt.diff <-sqrt(sum(diff2)) return(sqrt.diff) } calcnorm2=function(a,X){ lapply(X, calcnorm, a) } lapply(x.list, calcnorm, x.list) [[1]] [[1]][[1]] [1] 0 [[1]][[2]] [1] 31.75257 [[2]] [[2]][[1]] [1] 31.75257 [[2]][[2]] [1] 0 ### matrix version calcnorm.const=function(a,b){ return(sqrt((a-b)%*%(a-b))) } calcnorm2.const=function(a,data){...