r - How to perform element-wise statistics over numerous (distance) matrices -
i have several thousand distance matrices (converted matrix using as.dist()) , compute mean, sd, median etc each matrix element.
to illustrate:
matrix.a
1 7 1 5 2 1
matrix.b
2 3 4 1 1 3
etc...
for example, if have sum of individual elements do:
sum.matrix <- matrix.a + matrix.b
sum.matrix
3 10 5 6 3 4
but if have thousands of these matrices? , how can compute not sum each element means, sd etc? matrices stored in single list.
try
lst2 <- lapply(lst1, as.matrix) dim1 <- sapply(lst2, dim)[,1] l <- length(lst1) ar1 <- array(unlist(lst2), dim=c(dim1, l)) as.dist(apply(ar1, 1:2, sum)) as.dist(apply(ar1, 1:2, mean)) as.dist(apply(ar1, 1:2, sd))
data
set.seed(24) lst1 <- lapply(1:4, function(i) dist(sample(1:10,4, replace=true)))
Comments
Post a Comment