[R] looping through 3D array
arun
smartpink111 at yahoo.com
Thu Jan 9 21:46:46 CET 2014
Hi,
Try:
library(emdist)
set.seed(435)
results<- array(sample(1:400,120,replace=TRUE),dim=c(10,3,4))
res <- sapply(seq(dim(results)[1]),function(i) {x1 <- results[i,,]; x2 <- results; sapply(seq(dim(x2)[1]),function(i) emd2d(x1,x2[i,,]))})
dim(res)
#[1] 10 10
A.K.
On Thursday, January 9, 2014 3:25 PM, alex padron <alexpadron1082 at gmail.com> wrote:
I'll try to be clearer. in your example we have: results<- array(1:120,dim=c(10,3,4))
I want to do the following: compare results[1,,] with every matrix inside results. I then want to jump to results[2,,] and compare it to all of the other 10 matrices inside results and so on. so emd2d from the emdist package outputs a single value when comparing matrices and since your example has 10 matrices who are all being compared, the output should be 100 values.
Does that make sense?
-Alex
More information about the R-help
mailing list