Description Usage Arguments Details Value Author(s) References See Also Examples
Return a vector or list of values obtained by applying a function to margins of a GDS matrix or array.
1 2 3 4 |
node |
an object of class |
margin |
an integer giving the subscripts which the function will be applied over. E.g., for a matrix 1 indicates rows, 2 indicates columns |
FUN |
the function to be applied |
selection |
a list or NULL; if a list, it is a list of logical vectors according to dimensions indicating selection; if NULL, uses all data |
as.is |
returned value: a list, an integer vector, etc;
|
var.index |
if |
target.node |
NULL, an object of class |
.useraw |
use R RAW storage mode if integers can be stored in a byte, to reduce memory usage |
.value |
a vector of values to be replaced in the original data array, or NULL for nothing |
.substitute |
a vector of values after replacing, or NULL for
nothing; |
... |
optional arguments to |
The algorithm is optimized by blocking the computations to exploit the high-speed memory instead of disk.
When as.is="gdsnode"
and there are more than one
gdsn.class
object in target.node
, the user-defined
function should return a list with elements corresponding to
target.node
, or NULL
indicating no appending.
A vector or list of values.
Xiuwen Zheng
http://github.com/zhengxwen/gdsfmt
read.gdsn
, readex.gdsn
,
clusterApply.gdsn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | # cteate a GDS file
f <- createfn.gds("test.gds")
(n1 <- add.gdsn(f, "matrix", val=matrix(1:(10*6), nrow=10)))
read.gdsn(index.gdsn(f, "matrix"))
(n2 <- add.gdsn(f, "string",
val=matrix(paste("L", 1:(10*6), sep=","), nrow=10)))
read.gdsn(index.gdsn(f, "string"))
# Apply functions over rows of matrix
apply.gdsn(n1, margin=1, FUN=function(x) print(x), as.is="none")
apply.gdsn(n1, margin=1,
selection = list(rep(c(TRUE, FALSE), 5), rep(c(TRUE, FALSE), 3)),
FUN=function(x) print(x), as.is="none")
apply.gdsn(n1, margin=1, var.index="relative",
selection = list(rep(c(TRUE, FALSE), 5), rep(c(TRUE, FALSE), 3)),
FUN=function(i, x) { cat("index: ", i, ", ", sep=""); print(x) },
as.is="none")
apply.gdsn(n1, margin=1, var.index="absolute",
selection = list(rep(c(TRUE, FALSE), 5), rep(c(TRUE, FALSE), 3)),
FUN=function(i, x) { cat("index: ", i, ", ", sep=""); print(x) },
as.is="none")
apply.gdsn(n2, margin=1, FUN=function(x) print(x), as.is="none")
# Apply functions over columns of matrix
apply.gdsn(n1, margin=2, FUN=function(x) print(x), as.is="none")
apply.gdsn(n1, margin=2,
selection = list(rep(c(TRUE, FALSE), 5), rep(c(TRUE, FALSE), 3)),
FUN=function(x) print(x), as.is="none")
apply.gdsn(n2, margin=2,
selection = list(rep(c(TRUE, FALSE), 5), rep(c(TRUE, FALSE), 3)),
FUN=function(x) print(x), as.is="none")
apply.gdsn(n1, margin=1, FUN=function(x) print(x), as.is="none",
.value=16:40, .substitute=NA)
apply.gdsn(n1, margin=2, FUN=function(x) print(x), as.is="none",
.value=16:40, .substitute=NA)
# close
closefn.gds(f)
########################################################
#
# Append to a target GDS node
#
# cteate a GDS file
f <- createfn.gds("test.gds")
(n2 <- add.gdsn(f, "matrix", val=matrix(1:(10*6), nrow=10)))
(n2 <- add.gdsn(f, "string",
val=matrix(paste("L", 1:(10*6), sep=","), nrow=10)))
read.gdsn(index.gdsn(f, "string"))
n2.1 <- add.gdsn(f, "transpose.matrix", storage="int", valdim=c(6,0))
n2.1 <- add.gdsn(f, "transpose.string", storage="string", valdim=c(6,0))
# Apply functions over rows of matrix
apply.gdsn(n2, margin=1, FUN=`c`, as.is="gdsnode", target.node=n2.1)
# matrix transpose
read.gdsn(n2)
read.gdsn(n2.1)
# Apply functions over rows of matrix
apply.gdsn(n2, margin=1, FUN=`c`, as.is="gdsnode", target.node=n2.1)
# matrix transpose
read.gdsn(n2)
read.gdsn(n2.1)
# close
closefn.gds(f)
########################################################
#
# Append to multiple target GDS node
#
# cteate a GDS file
f <- createfn.gds("test.gds")
(n2 <- add.gdsn(f, "matrix", val=matrix(1:(10*6), nrow=10)))
n2.1 <- add.gdsn(f, "transpose.matrix", storage="int", valdim=c(6,0))
n2.2 <- add.gdsn(f, "n.matrix", storage="int", valdim=c(0))
# Apply functions over rows of matrix
apply.gdsn(n2, margin=1, FUN=function(x) list(x, x[1]),
as.is="gdsnode", target.node=list(n2.1, n2.2))
# matrix transpose
read.gdsn(n2)
read.gdsn(n2.1)
read.gdsn(n2.2)
# close
closefn.gds(f)
########################################################
#
# Multiple variables
#
# cteate a GDS file
f <- createfn.gds("test.gds")
X <- matrix(1:50, nrow=10)
Y <- matrix((1:50)/100, nrow=10)
Z1 <- factor(c(rep(c("ABC", "DEF", "ETD"), 3), "TTT"))
Z2 <- c(TRUE, FALSE, TRUE, FALSE, TRUE)
node.X <- add.gdsn(f, "X", X)
node.Y <- add.gdsn(f, "Y", Y)
node.Z1 <- add.gdsn(f, "Z1", Z1)
node.Z2 <- add.gdsn(f, "Z2", Z2)
v <- apply.gdsn(list(X=node.X, Y=node.Y, Z=node.Z1), margin=c(1, 1, 1),
FUN=print, as.is="none")
v <- apply.gdsn(list(X=node.X, Y=node.Y, Z=node.Z2), margin=c(2, 2, 1),
FUN=print)
v <- apply.gdsn(list(X=node.X, Y=node.Y, Z=node.Z2), margin=c(2, 2, 1),
FUN=print, .value=35:45, .substitute=NA)
v <- apply.gdsn(list(X=node.X, Y=node.Y, Z=node.Z2), margin=c(2, 2, 1),
FUN=print, .value=35:45, .substitute=NA)
# with selection
s1 <- rep(c(FALSE, TRUE), 5)
s2 <- c(TRUE, FALSE, TRUE, FALSE, TRUE)
v <- apply.gdsn(list(X=node.X, Y=node.Y, Z=node.Z1), margin=c(1, 1, 1),
selection = list(list(s1, s2), list(s1, s2), list(s1)),
FUN=function(x) print(x))
v <- apply.gdsn(list(X=node.X, Y=node.Y, Z=node.Z2), margin=c(2, 2, 1),
selection = list(list(s1, s2), list(s1, s2), list(s2)),
FUN=function(x) print(x))
# close the GDS file
closefn.gds(f)
# delete the temporary file
unlink("test.gds", force=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.