Common operations on DelayedArray objects
DelayedArray-utils.RdCommon operations on DelayedArray objects.
Details
The operations currently supported on DelayedArray objects are:
Delayed operations:
rbindandcbind!is.na,is.finite,is.infinite,is.nantype<-lengthsnchar,tolower,toupper,grepl,sub,gsubpmax2andpmin2scale(when the suppliedcenterandscaleare not TRUE)statistical functions like
dnorm,dbinom,dpois, anddlogis(for the Normal, Binomial, Poisson, and Logistic distribution, respectively) and related functions (documented in DelayedArray-stats)
Block-processed operations:
anyNA,which,nzwhichunique,tableall the members of the
Summarygroupmeanapply
Mix delayed and block-processed operations:
scale(when the suppliedcenterand/orscaleare TRUE)
See also
cbindin the base package for rbind/cbind'ing ordinary arrays.arbindandacbindin this package (DelayedArray) for binding ordinary arrays of arbitrary dimensions along their rows or columns.is.na,!,table,mean,apply, and%*%in the base package for the corresponding operations on ordinary arrays or matrices.DelayedArray-stats for statistical functions on DelayedArray objects.
matrixStats-methods for DelayedMatrix row/col summarization.
DelayedArray objects.
HDF5Array objects in the HDF5Array package.
S4groupGenericin the methods package for the members of theOps,Math, andMath2groups.paste2in the BiocGenerics package.
Examples
## ---------------------------------------------------------------------
## BIND DelayedArray OBJECTS
## ---------------------------------------------------------------------
## DelayedArray objects can be bound along their 1st (rows) or 2nd
## (columns) dimension with rbind() or cbind(). These operations are
## equivalent to arbind() and acbind(), respectively, and are all
## delayed.
## On 2D objects:
library(HDF5Array)
toy_h5 <- system.file("extdata", "toy.h5", package="HDF5Array")
h5ls(toy_h5)
#> group name otype dclass dim
#> 0 / M1 H5I_DATASET FLOAT 10000 x 150
#> 1 / M2 H5I_DATASET FLOAT 150 x 200
M1 <- HDF5Array(toy_h5, "M1")
M2 <- HDF5Array(toy_h5, "M2")
M12 <- rbind(M1, t(M2)) # delayed
M12
#> <10200 x 150> DelayedMatrix object of type "double":
#> [,1] [,2] [,3] ... [,149] [,150]
#> [1,] 0.44015009 0.02303051 0.11688992 . 0.6684808 0.9859835
#> [2,] 0.18883376 0.84313244 0.12153315 . 0.2886549 0.2750908
#> [3,] 0.99232698 0.22924928 0.20998143 . 0.4786133 0.7087926
#> [4,] 0.52631346 0.15438076 0.43283016 . 0.8715839 0.5870442
#> [5,] 0.62369062 0.27622849 0.54027815 . 0.3082406 0.2929455
#> ... . . . . . .
#> [10196,] 12.7122663 3.0340890 -1.4169923 . 6.924539558 2.991194399
#> [10197,] -1.1921119 12.1553961 10.3398257 . 13.541424135 10.732108410
#> [10198,] 11.2522507 6.2994228 0.8515161 . 3.639222663 -2.787210229
#> [10199,] 4.2025030 14.8541228 0.5208430 . 13.590451800 -0.007439521
#> [10200,] 7.2127450 3.4810124 8.8763231 . 2.134752800 7.164514768
colMeans(M12) # block-processed
#> [1] 0.5847215 0.5976341 0.5955049 0.5898834 0.5838513 0.5954696 0.5794771
#> [8] 0.6017740 0.5907392 0.5921464 0.5972239 0.5886432 0.5893401 0.5796834
#> [15] 0.5832794 0.5984886 0.5789885 0.5981562 0.5994559 0.5902942 0.5964307
#> [22] 0.6017652 0.5909635 0.5860712 0.6012874 0.5906832 0.5743288 0.5757507
#> [29] 0.5903412 0.5894468 0.6071159 0.5902459 0.5924693 0.5931731 0.5849759
#> [36] 0.5987650 0.5686553 0.5954116 0.5929792 0.5807617 0.5858967 0.5768919
#> [43] 0.5849780 0.5969409 0.5945609 0.5873373 0.5985127 0.5845567 0.5835624
#> [50] 0.5800856 0.5959954 0.5941727 0.5985898 0.5870470 0.6016754 0.5971824
#> [57] 0.5831226 0.5983267 0.5776760 0.5897750 0.5999326 0.5885997 0.5859833
#> [64] 0.5898483 0.5900072 0.5802166 0.5715231 0.5925759 0.5869830 0.5853867
#> [71] 0.6074465 0.5927962 0.5836831 0.5884932 0.6034180 0.5994154 0.5905539
#> [78] 0.5871405 0.5956231 0.5997698 0.5948899 0.5921457 0.5785114 0.5849732
#> [85] 0.5893467 0.5836812 0.5997758 0.5696571 0.5831440 0.5806131 0.5908729
#> [92] 0.5834960 0.5965191 0.5861503 0.5967210 0.5776620 0.5914219 0.5981962
#> [99] 0.5892449 0.5991614 0.5872962 0.5842013 0.5884512 0.5855686 0.5818349
#> [106] 0.5931897 0.5872042 0.5784551 0.5808937 0.5800662 0.5910112 0.5863131
#> [113] 0.6002801 0.5898960 0.5901466 0.5949233 0.5946853 0.5901424 0.5939904
#> [120] 0.5931327 0.5913019 0.5958614 0.5839785 0.5904047 0.5854432 0.5929187
#> [127] 0.6018140 0.5920462 0.5989337 0.5951392 0.5878220 0.5809505 0.5850140
#> [134] 0.5848444 0.5824954 0.5911507 0.5864913 0.6020472 0.5830223 0.5879107
#> [141] 0.5743987 0.5840778 0.5876115 0.6024942 0.5866054 0.5940235 0.5877663
#> [148] 0.5967996 0.5944947 0.6009553
## On objects with more than 2 dimensions:
example(arbind) # to create arrays a1, a2, a3
#>
#> arbind> a1 <- array(1:60, c(3, 5, 4),
#> arbind+ dimnames=list(NULL, paste0("A1y", 1:5), NULL))
#>
#> arbind> a2 <- array(101:240, c(7, 5, 4),
#> arbind+ dimnames=list(paste0("A2x", 1:7), paste0("A2y", 1:5), NULL))
#>
#> arbind> a3 <- array(10001:10100, c(5, 5, 4),
#> arbind+ dimnames=list(paste0("A3x", 1:5), NULL, paste0("A3z", 1:4)))
#>
#> arbind> abind(a1, a2, a3, along=1) # same as 'arbind(a1, a2, a3)'
#> , , A3z1
#>
#> A1y1 A1y2 A1y3 A1y4 A1y5
#> 1 4 7 10 13
#> 2 5 8 11 14
#> 3 6 9 12 15
#> A2x1 101 108 115 122 129
#> A2x2 102 109 116 123 130
#> A2x3 103 110 117 124 131
#> A2x4 104 111 118 125 132
#> A2x5 105 112 119 126 133
#> A2x6 106 113 120 127 134
#> A2x7 107 114 121 128 135
#> A3x1 10001 10006 10011 10016 10021
#> A3x2 10002 10007 10012 10017 10022
#> A3x3 10003 10008 10013 10018 10023
#> A3x4 10004 10009 10014 10019 10024
#> A3x5 10005 10010 10015 10020 10025
#>
#> , , A3z2
#>
#> A1y1 A1y2 A1y3 A1y4 A1y5
#> 16 19 22 25 28
#> 17 20 23 26 29
#> 18 21 24 27 30
#> A2x1 136 143 150 157 164
#> A2x2 137 144 151 158 165
#> A2x3 138 145 152 159 166
#> A2x4 139 146 153 160 167
#> A2x5 140 147 154 161 168
#> A2x6 141 148 155 162 169
#> A2x7 142 149 156 163 170
#> A3x1 10026 10031 10036 10041 10046
#> A3x2 10027 10032 10037 10042 10047
#> A3x3 10028 10033 10038 10043 10048
#> A3x4 10029 10034 10039 10044 10049
#> A3x5 10030 10035 10040 10045 10050
#>
#> , , A3z3
#>
#> A1y1 A1y2 A1y3 A1y4 A1y5
#> 31 34 37 40 43
#> 32 35 38 41 44
#> 33 36 39 42 45
#> A2x1 171 178 185 192 199
#> A2x2 172 179 186 193 200
#> A2x3 173 180 187 194 201
#> A2x4 174 181 188 195 202
#> A2x5 175 182 189 196 203
#> A2x6 176 183 190 197 204
#> A2x7 177 184 191 198 205
#> A3x1 10051 10056 10061 10066 10071
#> A3x2 10052 10057 10062 10067 10072
#> A3x3 10053 10058 10063 10068 10073
#> A3x4 10054 10059 10064 10069 10074
#> A3x5 10055 10060 10065 10070 10075
#>
#> , , A3z4
#>
#> A1y1 A1y2 A1y3 A1y4 A1y5
#> 46 49 52 55 58
#> 47 50 53 56 59
#> 48 51 54 57 60
#> A2x1 206 213 220 227 234
#> A2x2 207 214 221 228 235
#> A2x3 208 215 222 229 236
#> A2x4 209 216 223 230 237
#> A2x5 210 217 224 231 238
#> A2x6 211 218 225 232 239
#> A2x7 212 219 226 233 240
#> A3x1 10076 10081 10086 10091 10096
#> A3x2 10077 10082 10087 10092 10097
#> A3x3 10078 10083 10088 10093 10098
#> A3x4 10079 10084 10089 10094 10099
#> A3x5 10080 10085 10090 10095 10100
#>
#>
#> arbind> m2 <- matrix(1:35, nrow=7)
#>
#> arbind> abind(m2, a2, along=3)
#> , , 1
#>
#> A2y1 A2y2 A2y3 A2y4 A2y5
#> A2x1 1 8 15 22 29
#> A2x2 2 9 16 23 30
#> A2x3 3 10 17 24 31
#> A2x4 4 11 18 25 32
#> A2x5 5 12 19 26 33
#> A2x6 6 13 20 27 34
#> A2x7 7 14 21 28 35
#>
#> , , 2
#>
#> A2y1 A2y2 A2y3 A2y4 A2y5
#> A2x1 101 108 115 122 129
#> A2x2 102 109 116 123 130
#> A2x3 103 110 117 124 131
#> A2x4 104 111 118 125 132
#> A2x5 105 112 119 126 133
#> A2x6 106 113 120 127 134
#> A2x7 107 114 121 128 135
#>
#> , , 3
#>
#> A2y1 A2y2 A2y3 A2y4 A2y5
#> A2x1 136 143 150 157 164
#> A2x2 137 144 151 158 165
#> A2x3 138 145 152 159 166
#> A2x4 139 146 153 160 167
#> A2x5 140 147 154 161 168
#> A2x6 141 148 155 162 169
#> A2x7 142 149 156 163 170
#>
#> , , 4
#>
#> A2y1 A2y2 A2y3 A2y4 A2y5
#> A2x1 171 178 185 192 199
#> A2x2 172 179 186 193 200
#> A2x3 173 180 187 194 201
#> A2x4 174 181 188 195 202
#> A2x5 175 182 189 196 203
#> A2x6 176 183 190 197 204
#> A2x7 177 184 191 198 205
#>
#> , , 5
#>
#> A2y1 A2y2 A2y3 A2y4 A2y5
#> A2x1 206 213 220 227 234
#> A2x2 207 214 221 228 235
#> A2x3 208 215 222 229 236
#> A2x4 209 216 223 230 237
#> A2x5 210 217 224 231 238
#> A2x6 211 218 225 232 239
#> A2x7 212 219 226 233 240
#>
#>
#> arbind> abind(a2, m2, along=3)
#> , , 1
#>
#> A2y1 A2y2 A2y3 A2y4 A2y5
#> A2x1 101 108 115 122 129
#> A2x2 102 109 116 123 130
#> A2x3 103 110 117 124 131
#> A2x4 104 111 118 125 132
#> A2x5 105 112 119 126 133
#> A2x6 106 113 120 127 134
#> A2x7 107 114 121 128 135
#>
#> , , 2
#>
#> A2y1 A2y2 A2y3 A2y4 A2y5
#> A2x1 136 143 150 157 164
#> A2x2 137 144 151 158 165
#> A2x3 138 145 152 159 166
#> A2x4 139 146 153 160 167
#> A2x5 140 147 154 161 168
#> A2x6 141 148 155 162 169
#> A2x7 142 149 156 163 170
#>
#> , , 3
#>
#> A2y1 A2y2 A2y3 A2y4 A2y5
#> A2x1 171 178 185 192 199
#> A2x2 172 179 186 193 200
#> A2x3 173 180 187 194 201
#> A2x4 174 181 188 195 202
#> A2x5 175 182 189 196 203
#> A2x6 176 183 190 197 204
#> A2x7 177 184 191 198 205
#>
#> , , 4
#>
#> A2y1 A2y2 A2y3 A2y4 A2y5
#> A2x1 206 213 220 227 234
#> A2x2 207 214 221 228 235
#> A2x3 208 215 222 229 236
#> A2x4 209 216 223 230 237
#> A2x5 210 217 224 231 238
#> A2x6 211 218 225 232 239
#> A2x7 212 219 226 233 240
#>
#> , , 5
#>
#> A2y1 A2y2 A2y3 A2y4 A2y5
#> A2x1 1 8 15 22 29
#> A2x2 2 9 16 23 30
#> A2x3 3 10 17 24 31
#> A2x4 4 11 18 25 32
#> A2x5 5 12 19 26 33
#> A2x6 6 13 20 27 34
#> A2x7 7 14 21 28 35
#>
#>
#> arbind> abind(m2, m2+0.5, rev.along=0) # same as 'abind(m2, m2+0.5, along=3)'
#> , , 1
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 8 15 22 29
#> [2,] 2 9 16 23 30
#> [3,] 3 10 17 24 31
#> [4,] 4 11 18 25 32
#> [5,] 5 12 19 26 33
#> [6,] 6 13 20 27 34
#> [7,] 7 14 21 28 35
#>
#> , , 2
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1.5 8.5 15.5 22.5 29.5
#> [2,] 2.5 9.5 16.5 23.5 30.5
#> [3,] 3.5 10.5 17.5 24.5 31.5
#> [4,] 4.5 11.5 18.5 25.5 32.5
#> [5,] 5.5 12.5 19.5 26.5 33.5
#> [6,] 6.5 13.5 20.5 27.5 34.5
#> [7,] 7.5 14.5 21.5 28.5 35.5
#>
A1 <- DelayedArray(a1)
A2 <- DelayedArray(a2)
A3 <- DelayedArray(a3)
A123 <- rbind(A1, A2, A3) # delayed
A123
#> <15 x 5 x 4> DelayedArray object of type "integer":
#> ,,A3z1
#> A1y1 A1y2 A1y3 A1y4 A1y5
#> 1 4 7 10 13
#> 2 5 8 11 14
#> ... . . . . .
#> A3x4 10004 10009 10014 10019 10024
#> A3x5 10005 10010 10015 10020 10025
#>
#> ...
#>
#> ,,A3z4
#> A1y1 A1y2 A1y3 A1y4 A1y5
#> 46 49 52 55 58
#> 47 50 53 56 59
#> ... . . . . .
#> A3x4 10079 10084 10089 10094 10099
#> A3x5 10080 10085 10090 10095 10100
#>
## On 1D objects:
v1 <- array(11:15, 5, dimnames=list(LETTERS[1:5]))
v2 <- array(letters[1:3])
V1 <- DelayedArray(v1)
V2 <- DelayedArray(v2)
V12 <- rbind(V1, V2)
V12
#> <8> DelayedArray object of type "character":
#> A B C .
#> "11" "12" "13" . "b" "c"
if (FALSE) cbind(V1, V2) # Error! (the objects to cbind() must have at least 2
# dimensions)
# \dontrun{}
## Note that base::rbind() and base::cbind() do something completely
## different on ordinary arrays that are not matrices. They treat them
## as if they were vectors:
rbind(a1, a2, a3)
#> Warning: number of columns of result is not a multiple of vector length (arg 1)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
#> a1 1 2 3 4 5 6 7 8 9 10 11 12
#> a2 101 102 103 104 105 106 107 108 109 110 111 112
#> a3 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012
#> [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24]
#> a1 13 14 15 16 17 18 19 20 21 22 23 24
#> a2 113 114 115 116 117 118 119 120 121 122 123 124
#> a3 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024
#> [,25] [,26] [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36]
#> a1 25 26 27 28 29 30 31 32 33 34 35 36
#> a2 125 126 127 128 129 130 131 132 133 134 135 136
#> a3 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036
#> [,37] [,38] [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48]
#> a1 37 38 39 40 41 42 43 44 45 46 47 48
#> a2 137 138 139 140 141 142 143 144 145 146 147 148
#> a3 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048
#> [,49] [,50] [,51] [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60]
#> a1 49 50 51 52 53 54 55 56 57 58 59 60
#> a2 149 150 151 152 153 154 155 156 157 158 159 160
#> a3 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060
#> [,61] [,62] [,63] [,64] [,65] [,66] [,67] [,68] [,69] [,70] [,71] [,72]
#> a1 1 2 3 4 5 6 7 8 9 10 11 12
#> a2 161 162 163 164 165 166 167 168 169 170 171 172
#> a3 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072
#> [,73] [,74] [,75] [,76] [,77] [,78] [,79] [,80] [,81] [,82] [,83] [,84]
#> a1 13 14 15 16 17 18 19 20 21 22 23 24
#> a2 173 174 175 176 177 178 179 180 181 182 183 184
#> a3 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084
#> [,85] [,86] [,87] [,88] [,89] [,90] [,91] [,92] [,93] [,94] [,95] [,96]
#> a1 25 26 27 28 29 30 31 32 33 34 35 36
#> a2 185 186 187 188 189 190 191 192 193 194 195 196
#> a3 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096
#> [,97] [,98] [,99] [,100] [,101] [,102] [,103] [,104] [,105] [,106] [,107]
#> a1 37 38 39 40 41 42 43 44 45 46 47
#> a2 197 198 199 200 201 202 203 204 205 206 207
#> a3 10097 10098 10099 10100 10001 10002 10003 10004 10005 10006 10007
#> [,108] [,109] [,110] [,111] [,112] [,113] [,114] [,115] [,116] [,117] [,118]
#> a1 48 49 50 51 52 53 54 55 56 57 58
#> a2 208 209 210 211 212 213 214 215 216 217 218
#> a3 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018
#> [,119] [,120] [,121] [,122] [,123] [,124] [,125] [,126] [,127] [,128] [,129]
#> a1 59 60 1 2 3 4 5 6 7 8 9
#> a2 219 220 221 222 223 224 225 226 227 228 229
#> a3 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029
#> [,130] [,131] [,132] [,133] [,134] [,135] [,136] [,137] [,138] [,139] [,140]
#> a1 10 11 12 13 14 15 16 17 18 19 20
#> a2 230 231 232 233 234 235 236 237 238 239 240
#> a3 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040
cbind(a1, a2, a3)
#> Warning: number of rows of result is not a multiple of vector length (arg 1)
#> a1 a2 a3
#> [1,] 1 101 10001
#> [2,] 2 102 10002
#> [3,] 3 103 10003
#> [4,] 4 104 10004
#> [5,] 5 105 10005
#> [6,] 6 106 10006
#> [7,] 7 107 10007
#> [8,] 8 108 10008
#> [9,] 9 109 10009
#> [10,] 10 110 10010
#> [11,] 11 111 10011
#> [12,] 12 112 10012
#> [13,] 13 113 10013
#> [14,] 14 114 10014
#> [15,] 15 115 10015
#> [16,] 16 116 10016
#> [17,] 17 117 10017
#> [18,] 18 118 10018
#> [19,] 19 119 10019
#> [20,] 20 120 10020
#> [21,] 21 121 10021
#> [22,] 22 122 10022
#> [23,] 23 123 10023
#> [24,] 24 124 10024
#> [25,] 25 125 10025
#> [26,] 26 126 10026
#> [27,] 27 127 10027
#> [28,] 28 128 10028
#> [29,] 29 129 10029
#> [30,] 30 130 10030
#> [31,] 31 131 10031
#> [32,] 32 132 10032
#> [33,] 33 133 10033
#> [34,] 34 134 10034
#> [35,] 35 135 10035
#> [36,] 36 136 10036
#> [37,] 37 137 10037
#> [38,] 38 138 10038
#> [39,] 39 139 10039
#> [40,] 40 140 10040
#> [41,] 41 141 10041
#> [42,] 42 142 10042
#> [43,] 43 143 10043
#> [44,] 44 144 10044
#> [45,] 45 145 10045
#> [46,] 46 146 10046
#> [47,] 47 147 10047
#> [48,] 48 148 10048
#> [49,] 49 149 10049
#> [50,] 50 150 10050
#> [51,] 51 151 10051
#> [52,] 52 152 10052
#> [53,] 53 153 10053
#> [54,] 54 154 10054
#> [55,] 55 155 10055
#> [56,] 56 156 10056
#> [57,] 57 157 10057
#> [58,] 58 158 10058
#> [59,] 59 159 10059
#> [60,] 60 160 10060
#> [61,] 1 161 10061
#> [62,] 2 162 10062
#> [63,] 3 163 10063
#> [64,] 4 164 10064
#> [65,] 5 165 10065
#> [66,] 6 166 10066
#> [67,] 7 167 10067
#> [68,] 8 168 10068
#> [69,] 9 169 10069
#> [70,] 10 170 10070
#> [71,] 11 171 10071
#> [72,] 12 172 10072
#> [73,] 13 173 10073
#> [74,] 14 174 10074
#> [75,] 15 175 10075
#> [76,] 16 176 10076
#> [77,] 17 177 10077
#> [78,] 18 178 10078
#> [79,] 19 179 10079
#> [80,] 20 180 10080
#> [81,] 21 181 10081
#> [82,] 22 182 10082
#> [83,] 23 183 10083
#> [84,] 24 184 10084
#> [85,] 25 185 10085
#> [86,] 26 186 10086
#> [87,] 27 187 10087
#> [88,] 28 188 10088
#> [89,] 29 189 10089
#> [90,] 30 190 10090
#> [91,] 31 191 10091
#> [92,] 32 192 10092
#> [93,] 33 193 10093
#> [94,] 34 194 10094
#> [95,] 35 195 10095
#> [96,] 36 196 10096
#> [97,] 37 197 10097
#> [98,] 38 198 10098
#> [99,] 39 199 10099
#> [100,] 40 200 10100
#> [101,] 41 201 10001
#> [102,] 42 202 10002
#> [103,] 43 203 10003
#> [104,] 44 204 10004
#> [105,] 45 205 10005
#> [106,] 46 206 10006
#> [107,] 47 207 10007
#> [108,] 48 208 10008
#> [109,] 49 209 10009
#> [110,] 50 210 10010
#> [111,] 51 211 10011
#> [112,] 52 212 10012
#> [113,] 53 213 10013
#> [114,] 54 214 10014
#> [115,] 55 215 10015
#> [116,] 56 216 10016
#> [117,] 57 217 10017
#> [118,] 58 218 10018
#> [119,] 59 219 10019
#> [120,] 60 220 10020
#> [121,] 1 221 10021
#> [122,] 2 222 10022
#> [123,] 3 223 10023
#> [124,] 4 224 10024
#> [125,] 5 225 10025
#> [126,] 6 226 10026
#> [127,] 7 227 10027
#> [128,] 8 228 10028
#> [129,] 9 229 10029
#> [130,] 10 230 10030
#> [131,] 11 231 10031
#> [132,] 12 232 10032
#> [133,] 13 233 10033
#> [134,] 14 234 10034
#> [135,] 15 235 10035
#> [136,] 16 236 10036
#> [137,] 17 237 10037
#> [138,] 18 238 10038
#> [139,] 19 239 10039
#> [140,] 20 240 10040
rbind(v1, v2)
#> Warning: number of columns of result is not a multiple of vector length (arg 2)
#> A B C D E
#> v1 "11" "12" "13" "14" "15"
#> v2 "a" "b" "c" "a" "b"
cbind(v1, v2)
#> Warning: number of rows of result is not a multiple of vector length (arg 2)
#> v1 v2
#> A "11" "a"
#> B "12" "b"
#> C "13" "c"
#> D "14" "a"
#> E "15" "b"
## Also note that DelayedArray objects of arbitrary dimensions can be
## stored inside a DataFrame object as long as they all have the same
## first dimension (nrow()):
DF <- DataFrame(M=I(tail(M1, n=5)), A=I(A3), V=I(V1))
DF[-3, ]
#> DataFrame with 4 rows and 3 columns
#> M
#> <DelayedMatrix>
#> 1 0.691832306561992:0.493223202414811:0.692104285117239:...
#> 2 0.0157738912384957:0.641924865543842:0.706047241110355:...
#> 3 0.291226184694096:0.217180676292628:0.548560027033091:...
#> 4 0.875399844022468:0.346653513377532:0.0666172914206982:...
#> A V
#> <DelayedArray> <DelayedArray>
#> 1 10001:10006:10011:... 11
#> 2 10002:10007:10012:... 12
#> 3 10004:10009:10014:... 14
#> 4 10005:10010:10015:... 15
DF2 <- rbind(DF, DF)
DF2$V
#> <10> DelayedArray object of type "integer":
#> A B C D . B C D E
#> 11 12 13 14 . 12 13 14 15
## Sanity checks:
m1 <- as.matrix(M1)
m2 <- as.matrix(M2)
stopifnot(identical(rbind(m1, t(m2)), as.matrix(M12)))
stopifnot(identical(arbind(a1, a2, a3), as.array(A123)))
stopifnot(identical(arbind(v1, v2), as.array(V12)))
stopifnot(identical(rbind(DF$M, DF$M), DF2$M))
stopifnot(identical(rbind(DF$A, DF$A), DF2$A))
stopifnot(identical(rbind(DF$V, DF$V), DF2$V))
## ---------------------------------------------------------------------
## MORE OPERATIONS
## ---------------------------------------------------------------------
M1 >= 0.5 & M1 < 0.75 # delayed
#> <10000 x 150> DelayedMatrix object of type "logical":
#> [,1] [,2] [,3] ... [,149] [,150]
#> [1,] FALSE FALSE FALSE . TRUE FALSE
#> [2,] FALSE FALSE FALSE . FALSE FALSE
#> [3,] FALSE FALSE FALSE . FALSE TRUE
#> [4,] TRUE FALSE FALSE . FALSE TRUE
#> [5,] TRUE FALSE TRUE . FALSE FALSE
#> ... . . . . . .
#> [9996,] TRUE FALSE TRUE . TRUE FALSE
#> [9997,] FALSE TRUE TRUE . FALSE FALSE
#> [9998,] TRUE FALSE TRUE . FALSE FALSE
#> [9999,] FALSE FALSE TRUE . FALSE FALSE
#> [10000,] FALSE FALSE FALSE . TRUE FALSE
log(M1) # delayed
#> <10000 x 150> DelayedMatrix object of type "double":
#> [,1] [,2] [,3] ... [,149] [,150]
#> [1,] -0.820639505 -3.770935241 -2.146522675 . -0.40274758 -0.01411563
#> [2,] -1.666888233 -0.170631225 -2.107568204 . -1.24252354 -1.29065419
#> [3,] -0.007702612 -1.472945288 -1.560736183 . -0.73686236 -0.34419236
#> [4,] -0.641858317 -1.868333264 -0.837409871 . -0.13744310 -0.53265512
#> [5,] -0.472100843 -1.286526883 -0.615671174 . -1.17687460 -1.22776874
#> ... . . . . . .
#> [9996,] -0.3684117 -0.7067935 -0.3680186 . -0.68306548 -1.74293095
#> [9997,] -4.1493992 -0.4432840 -0.3480731 . -0.21275385 -2.36738637
#> [9998,] -0.6566335 -0.2402248 -0.6626868 . -0.27081827 -1.69440209
#> [9999,] -1.2336550 -1.5270257 -0.6004586 . -1.92866532 -0.02557344
#> [10000,] -0.1330745 -1.0594295 -2.7087911 . -0.33689843 -1.50777810
pmax2(M2, 0) # delayed
#> <150 x 200> DelayedMatrix object of type "double":
#> [,1] [,2] [,3] ... [,199] [,200]
#> [1,] 9.0325451 0.0000000 0.0000000 . 4.202503 7.212745
#> [2,] 0.5603696 1.4590217 1.6268596 . 14.854123 3.481012
#> [3,] 8.1094489 2.9110584 12.7574103 . 0.520843 8.876323
#> [4,] 5.8518510 6.4912588 13.8403073 . 8.795605 12.342113
#> [5,] 0.0000000 10.1040618 10.6219819 . 8.756145 3.130079
#> ... . . . . . .
#> [146,] 11.2827878 0.0000000 5.4538427 . 0.0000000 6.0707772
#> [147,] 0.0000000 10.5172435 0.0000000 . 0.8243989 0.0000000
#> [148,] 0.9635204 13.8644578 11.6860867 . 5.7615046 1.6889923
#> [149,] 12.6951503 11.6835890 13.4213585 . 13.5904518 2.1347528
#> [150,] 0.0000000 9.9152485 8.6534266 . 0.0000000 7.1645148
type(M2) <- "integer" # delayed
M2
#> <150 x 200> DelayedMatrix object of type "integer":
#> [,1] [,2] [,3] [,4] ... [,197] [,198] [,199] [,200]
#> [1,] 9 0 -3 14 . -1 11 4 7
#> [2,] 0 1 1 14 . 12 6 14 3
#> [3,] 8 2 12 6 . 10 0 0 8
#> [4,] 5 6 13 12 . -1 6 8 12
#> [5,] 0 10 10 -4 . 9 14 8 3
#> ... . . . . . . . . .
#> [146,] 11 -3 5 0 . 1 6 0 6
#> [147,] -2 10 -2 -1 . 3 9 0 -3
#> [148,] 0 13 11 -2 . 2 -4 5 1
#> [149,] 12 11 13 8 . 13 3 13 2
#> [150,] -1 9 8 9 . 10 -2 0 7
## table() is block-processed:
a4 <- array(sample(50L, 2000000L, replace=TRUE), c(200, 4, 2500))
A4 <- as(a4, "HDF5Array")
table(A4)
#> A4
#> 1 2 3 4 5 6 7 8 9 10 11 12 13
#> 39772 39890 40222 39993 40015 39755 40131 39852 40008 40147 39817 39957 40120
#> 14 15 16 17 18 19 20 21 22 23 24 25 26
#> 40145 40133 39909 40077 40051 40302 39741 39868 40209 39965 40113 40149 40131
#> 27 28 29 30 31 32 33 34 35 36 37 38 39
#> 40298 39619 39577 40004 40124 40007 40288 40177 39829 39862 40125 39987 39737
#> 40 41 42 43 44 45 46 47 48 49 50
#> 40108 39973 39894 40353 39714 40170 40006 39869 39754 39800 40253
a5 <- array(sample(20L, 2000000L, replace=TRUE), c(200, 4, 2500))
A5 <- as(a5, "HDF5Array")
table(A5)
#> A5
#> 1 2 3 4 5 6 7 8 9 10 11
#> 99258 99817 100508 99704 100004 99944 100198 100383 99842 100178 99847
#> 12 13 14 15 16 17 18 19 20
#> 99909 99630 100031 100548 99646 99982 100595 100379 99597
A4 - 2 * A5 # delayed
#> <200 x 4 x 2500> DelayedArray object of type "double":
#> ,,1
#> [,1] [,2] [,3] [,4]
#> [1,] 10 -24 19 23
#> [2,] 10 13 28 -30
#> ... . . . .
#> [199,] -19 -32 -22 6
#> [200,] 26 -8 7 11
#>
#> ...
#>
#> ,,2500
#> [,1] [,2] [,3] [,4]
#> [1,] -14 -23 24 -18
#> [2,] -10 -14 12 3
#> ... . . . .
#> [199,] -9 -4 32 18
#> [200,] 21 24 7 14
#>
table(A4 - 2 * A5) # block-processed
#>
#> -39 -38 -37 -36 -35 -34 -33 -32 -31 -30 -29 -28 -27
#> 1951 2020 3928 4025 6068 6081 7936 7945 10022 9865 12078 11883 14198
#> -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14
#> 13988 16101 15969 18053 18033 20018 19829 22107 21890 23936 23842 26135 25966
#> -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
#> 27927 27996 30267 30068 32219 32338 33945 33701 35884 35930 38120 37866 40144
#> 0 1 2 3 4 5 6 7 8 9 10 11 12
#> 40039 40013 40038 39982 39966 39778 39751 40299 40063 39986 40174 38094 38328
#> 13 14 15 16 17 18 19 20 21 22 23 24 25
#> 35892 36057 34160 34011 31945 31904 30024 29978 27699 28097 26188 25943 23855
#> 26 27 28 29 30 31 32 33 34 35 36 37 38
#> 23953 22090 22019 20041 20060 17880 17842 16086 15777 13747 13900 11930 12088
#> 39 40 41 42 43 44 45 46 47 48
#> 9992 10011 8048 8214 5971 5827 4024 4013 1961 1990
## range() is block-processed:
range(A4 - 2 * A5)
#> [1] -39 48
range(M1)
#> [1] 1.552980e-07 9.999996e-01
cmeans <- colMeans(M2) # block-processed
sweep(M2, 2, cmeans) # delayed
#> <150 x 200> DelayedMatrix object of type "double":
#> [,1] [,2] [,3] ... [,199] [,200]
#> [1,] 3.4266667 -4.9733333 -8.0733333 . -0.7333333 2.2333333
#> [2,] -5.5733333 -3.9733333 -4.0733333 . 9.2666667 -1.7666667
#> [3,] 2.4266667 -2.9733333 6.9266667 . -4.7333333 3.2333333
#> [4,] -0.5733333 1.0266667 7.9266667 . 3.2666667 7.2333333
#> [5,] -5.5733333 5.0266667 4.9266667 . 3.2666667 -1.7666667
#> ... . . . . . .
#> [146,] 5.42666667 -7.97333333 -0.07333333 . -4.7333333 1.2333333
#> [147,] -7.57333333 5.02666667 -7.07333333 . -4.7333333 -7.7666667
#> [148,] -5.57333333 8.02666667 5.92666667 . 0.2666667 -3.7666667
#> [149,] 6.42666667 6.02666667 7.92666667 . 8.2666667 -2.7666667
#> [150,] -6.57333333 4.02666667 2.92666667 . -4.7333333 2.2333333
scale(M2) # delayed & block-processed
#> <150 x 200> DelayedMatrix object of type "double":
#> [,1] [,2] [,3] ... [,199] [,200]
#> [1,] 0.6800869 -0.8862712 -1.4250577 . -0.1359827 0.4495828
#> [2,] -1.1061336 -0.7080665 -0.7190010 . 1.7183263 -0.3556401
#> [3,] 0.4816180 -0.5298619 1.2226548 . -0.8777062 0.6508886
#> [4,] -0.1137889 0.1829568 1.3991690 . 0.6057409 1.4561115
#> [5,] -1.1061336 0.8957755 0.8696265 . 0.6057409 -0.3556401
#> ... . . . . . .
#> [146,] 1.07702482 -1.42088520 -0.01294437 . -0.87770622 0.24827708
#> [147,] -1.50307150 0.89577545 -1.24854355 . -0.87770622 -1.56347459
#> [148,] -1.10613360 1.43038945 1.04614063 . 0.04944824 -0.75825163
#> [149,] 1.27549377 1.07398012 1.39916897 . 1.53289537 -0.55694589
#> [150,] -1.30460255 0.71757079 0.51659813 . -0.87770622 0.44958282
scale(M2, center=FALSE, scale=10) # delayed
#> <150 x 200> DelayedMatrix object of type "double":
#> [,1] [,2] [,3] ... [,199] [,200]
#> [1,] 0.9 0.0 -0.3 . 0.4 0.7
#> [2,] 0.0 0.1 0.1 . 1.4 0.3
#> [3,] 0.8 0.2 1.2 . 0.0 0.8
#> [4,] 0.5 0.6 1.3 . 0.8 1.2
#> [5,] 0.0 1.0 1.0 . 0.8 0.3
#> ... . . . . . .
#> [146,] 1.1 -0.3 0.5 . 0.0 0.6
#> [147,] -0.2 1.0 -0.2 . 0.0 -0.3
#> [148,] 0.0 1.3 1.1 . 0.5 0.1
#> [149,] 1.2 1.1 1.3 . 1.3 0.2
#> [150,] -0.1 0.9 0.8 . 0.0 0.7
paste2(A3, letters[1:5]) # delayed
#> <5 x 5 x 4> DelayedArray object of type "character":
#> ,,A3z1
#> [,1] [,2] [,3] [,4] [,5]
#> A3x1 "10001a" "10006a" "10011a" "10016a" "10021a"
#> A3x2 "10002b" "10007b" "10012b" "10017b" "10022b"
#> A3x3 "10003c" "10008c" "10013c" "10018c" "10023c"
#> A3x4 "10004d" "10009d" "10014d" "10019d" "10024d"
#> A3x5 "10005e" "10010e" "10015e" "10020e" "10025e"
#>
#> ...
#>
#> ,,A3z4
#> [,1] [,2] [,3] [,4] [,5]
#> A3x1 "10076a" "10081a" "10086a" "10091a" "10096a"
#> A3x2 "10077b" "10082b" "10087b" "10092b" "10097b"
#> A3x3 "10078c" "10083c" "10088c" "10093c" "10098c"
#> A3x4 "10079d" "10084d" "10089d" "10094d" "10099d"
#> A3x5 "10080e" "10085e" "10090e" "10095e" "10100e"
#>
A6 <- add_prefix("ID", A3) # delayed
add_suffix(A6, ".fasta") # delayed
#> <5 x 5 x 4> DelayedArray object of type "character":
#> ,,A3z1
#> [,1] [,2] [,3] [,4]
#> A3x1 "10001ID.fasta" "10006ID.fasta" "10011ID.fasta" "10016ID.fasta"
#> A3x2 "10002ID.fasta" "10007ID.fasta" "10012ID.fasta" "10017ID.fasta"
#> A3x3 "10003ID.fasta" "10008ID.fasta" "10013ID.fasta" "10018ID.fasta"
#> A3x4 "10004ID.fasta" "10009ID.fasta" "10014ID.fasta" "10019ID.fasta"
#> A3x5 "10005ID.fasta" "10010ID.fasta" "10015ID.fasta" "10020ID.fasta"
#> [,5]
#> A3x1 "10021ID.fasta"
#> A3x2 "10022ID.fasta"
#> A3x3 "10023ID.fasta"
#> A3x4 "10024ID.fasta"
#> A3x5 "10025ID.fasta"
#>
#> ...
#>
#> ,,A3z4
#> [,1] [,2] [,3] [,4]
#> A3x1 "10076ID.fasta" "10081ID.fasta" "10086ID.fasta" "10091ID.fasta"
#> A3x2 "10077ID.fasta" "10082ID.fasta" "10087ID.fasta" "10092ID.fasta"
#> A3x3 "10078ID.fasta" "10083ID.fasta" "10088ID.fasta" "10093ID.fasta"
#> A3x4 "10079ID.fasta" "10084ID.fasta" "10089ID.fasta" "10094ID.fasta"
#> A3x5 "10080ID.fasta" "10085ID.fasta" "10090ID.fasta" "10095ID.fasta"
#> [,5]
#> A3x1 "10096ID.fasta"
#> A3x2 "10097ID.fasta"
#> A3x3 "10098ID.fasta"
#> A3x4 "10099ID.fasta"
#> A3x5 "10100ID.fasta"
#>