search for: calcnorm

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

2013 Mar 10
2
list + lapply insead of matrix + apply
...list manipulation. Although it seems easier to do it in matrix form, but I need it in list form. I have a matrix x <- matrix(c(12.1, 3.44, 0.1, 3, 12, 33.1, 1.1, 23), nrow=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....