Just use apply() and indexing instead!
results[,,apply(results,3,sum)&TRUE]
## will do it.
However, note that numerical error may make a hash of this. So safer
would be something like:
eps <- 1e-15 ## i.e. something small
results[,,abs(apply(results,3,sum))>eps]
Cheers,
Bert
Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
H. Gilbert Welch
On Thu, Jan 9, 2014 at 7:23 PM, arun <smartpink111 at yahoo.com>
wrote:> Hi Alex,
> Try:
> set.seed(345)
> results<- array(sample(-5:5,120,replace=TRUE),dim=c(10,3,4))
> indx <- !!apply(results,1,sum)
> library(plyr)
> results2 <- laply(lapply(seq(dim(results)[1]),function(i)
results[i,,])[indx],identity)
> attr(results2,"dimnames") <- NULL
> dim(results2)
> #[1] 9 3 4
>
> A.K.
>
>
>
> I have a 3D array with 13,000 11x8 matrices.
>
> dim(results
> [1] 13000 11 8
>
> Some matrices in the array add up to 0. For example
>
> sum(results[1,,])==0
> [1] TRUE
>
> I would like to remove these. How can I do this?
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.