### Name: simpleApply
### Title: simpleApply
### Aliases: simpleApply
### Keywords: iteration

### ** Examples


a <- array(c(1:30),dim=c(3,2,5))
r <- simpleApply(a, 1, function(x){return(x[2,5])}, 1)
stopifnot( all(r == matrix(data=c(28:30))))

r <- simpleApply(a, 2, function(x){return(x[,])}, c(3,5))
stopifnot( all( a == aperm(r,c(2,1,3)) ) )

vec <- 1:10; dim(vec) <- c(10,1)
mat <- matrix(data=rep(1:10,4),nrow=10,ncol=4,byrow=FALSE)
r <- simpleApply(mat,1,function(y){return(mean(y))},1)
stopifnot(all(r==vec))

r <- simpleApply(mat, 1:2, function(x) return(x), 1)
stopifnot( all(r[,,1] == mat) )

r <- simpleApply(a, c(1,3) , function(x) return(x), dim(a)[2])
stopifnot( all(aperm(r[,,],c(1,3,2)) == a) )

r <- simpleApply(a, 1:2, function(x) return(x[2]), 1)
stopifnot( all(r[,,] == a[,,2]) )

r <- simpleApply(a, 1, function(x) return(x), c(dim(a)[2],dim(a)[3]))
stopifnot( all( r== a ) )

 ## Don't show: 

r <- simpleApply(matrix(c(1, 2)), 1, sum, 1)
stopifnot( all(r == matrix(c(1,2))) )

a <- array(c(1:30),dim=c(3,2,5))
r <- simpleApply(a, 1, function(x){return(x[1])}, 1)
stopifnot( all(r == matrix(data=c(1:3))))

r <- simpleApply(a, 1, function(x){return(x[1,3])}, 1)
stopifnot( all(r == matrix(data=c(13:15))))

r <- simpleApply(a, 1, function(x){return(x[,])}, c(2,5))
stopifnot( all( a == r))

r <- simpleApply(a, 3, function(x){return(x[,])}, c(3,2))
stopifnot( all( a == aperm(r,c(2,3,1)) ) )

r2 <- simpleApply(a, 1, function(x){ return(as.vector(x))}, 10)

r <- simpleApply(a, 1:3, function(x) return(x), 1)
stopifnot( all(r[,,,1] == a) )

r <- simpleApply(a, 1:2, function(x) return(x), dim(a)[3])
stopifnot( all(r[,,] == a) )

r <- simpleApply(a, 1:2, function(x) return(x[1]), 1)

r <- simpleApply(a, 1:2, function(x) return(x[1]), 1)
stopifnot( all(r[,,] == a[,,1]) )

a <- array(1, dim=c(2,3,2))
b <- simpleApply(a, c(1,2), function(x){ return(x)}, 2)
stopifnot( all(a == b) )
a <- array(1, dim=c(2,1,2))
b <- simpleApply(a, c(1,2), function(x){ return(x)}, 2)

 ## End Don't show

        


