R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("abind-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('abind') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "abind" > > ### * abind > > flush(stderr()); flush(stdout()) > > ### Name: abind > ### Title: Combine multi-dimensional arrays > ### Aliases: abind > ### Keywords: manip array > > ### ** Examples > > # Five different ways of binding together two matrices > x <- matrix(1:12,3,4) > y <- x+100 > dim(abind(x,y,along=0)) # binds on new dimension before first [1] 2 3 4 > dim(abind(x,y,along=1)) # binds on first dimension [1] 6 4 > dim(abind(x,y,along=1.5)) [1] 3 2 4 > dim(abind(x,y,along=2)) [1] 3 8 > dim(abind(x,y,along=3)) [1] 3 4 2 > dim(abind(x,y,rev.along=1)) # binds on last dimension [1] 3 8 > dim(abind(x,y,rev.along=0)) # binds on new dimension after last [1] 3 4 2 > > # Unlike cbind or rbind in that the default is to bind > # along the last dimension of the inputs, which for vectors > # means the result is a vector (because a vector is > # treated as an array with length(dim(x))==1). > abind(x=1:4,y=5:8) x1 x2 x3 x4 y1 y2 y3 y4 1 2 3 4 5 6 7 8 > # Like cbind > abind(x=1:4,y=5:8,along=2) x y [1,] 1 5 [2,] 2 6 [3,] 3 7 [4,] 4 8 > abind(x=1:4,matrix(5:20,nrow=4),along=2) x [1,] 1 5 9 13 17 [2,] 2 6 10 14 18 [3,] 3 7 11 15 19 [4,] 4 8 12 16 20 > abind(1:4,matrix(5:20,nrow=4),along=2) [,1] [,2] [,3] [,4] [,5] [1,] 1 5 9 13 17 [2,] 2 6 10 14 18 [3,] 3 7 11 15 19 [4,] 4 8 12 16 20 > # Like rbind > abind(x=1:4,matrix(5:20,nrow=4),along=1) [,1] [,2] [,3] [,4] x 1 2 3 4 5 9 13 17 6 10 14 18 7 11 15 19 8 12 16 20 > abind(1:4,matrix(5:20,nrow=4),along=1) [,1] [,2] [,3] [,4] [1,] 1 2 3 4 [2,] 5 9 13 17 [3,] 6 10 14 18 [4,] 7 11 15 19 [5,] 8 12 16 20 > # Create a 3-d array out of two matrices > abind(x=matrix(1:16,nrow=4),y=matrix(17:32,nrow=4),along=3) , , x [,1] [,2] [,3] [,4] [1,] 1 5 9 13 [2,] 2 6 10 14 [3,] 3 7 11 15 [4,] 4 8 12 16 , , y [,1] [,2] [,3] [,4] [1,] 17 21 25 29 [2,] 18 22 26 30 [3,] 19 23 27 31 [4,] 20 24 28 32 > > > > cleanEx(); ..nameEx <- "adrop" > > ### * adrop > > flush(stderr()); flush(stdout()) > > ### Name: adrop > ### Title: Drop dimensions of an array object > ### Aliases: adrop > ### Keywords: manip array > > ### ** Examples > > x <- array(1:24,dim=c(2,3,4),dimnames=list(letters[1:2],LETTERS[1:3],letters[23:26])) > adrop(x[1,,,drop=FALSE],drop=1) w x y z A 1 7 13 19 B 3 9 15 21 C 5 11 17 23 > adrop(x[,1,,drop=FALSE],drop=2) w x y z a 1 7 13 19 b 2 8 14 20 > adrop(x[,,1,drop=FALSE],drop=3) A B C a 1 3 5 b 2 4 6 > adrop(x[1,1,1,drop=FALSE],drop=1) w A 1 > adrop(x[1,1,1,drop=FALSE],drop=2) w a 1 > adrop(x[1,1,1,drop=FALSE],drop=3) A a 1 > adrop(x[1,1,1,drop=FALSE],drop=1:2) w 1 > adrop(x[1,1,1,drop=FALSE],drop=1:2,one.d=TRUE) w 1 > adrop(x[1,1,1,drop=FALSE],drop=1:2,named=FALSE) [1] 1 > dim(adrop(x[1,1,1,drop=FALSE],drop=1:2,one.d=TRUE)) [1] 1 > dimnames(adrop(x[1,1,1,drop=FALSE],drop=1:2,one.d=TRUE)) [[1]] [1] "w" > names(adrop(x[1,1,1,drop=FALSE],drop=1:2,one.d=TRUE)) [1] "w" > dim(adrop(x[1,1,1,drop=FALSE],drop=1:2)) NULL > dimnames(adrop(x[1,1,1,drop=FALSE],drop=1:2)) NULL > names(adrop(x[1,1,1,drop=FALSE],drop=1:2)) [1] "w" > > > > ### *