Delia, the idea of creating a minimum, complete and verifiable example as Mpaladino tells you is essential for those who we are on the other side, on the one hand to understand the problem and on the other it saves us many difficulties. Luckily, in R , playing your example is very simple. You mention a list of 1000 items, where each one is a data.frame
of 22 columns and 16 rows, something like this:
# Creamos un dataframe como el ejemplo
df <- data.frame(matrix(1:(22*16), nrow=16))
df <- df[rep(seq_len(nrow(df)),1000),]
mdresult <- split(df,rep(1:ceiling(nrow(df)/16),each=16)[1:nrow(df)])
If we see the first data.frame
of the list with mdresult[[1]]
:
X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21 X22
1 1 17 33 49 65 81 97 113 129 145 161 177 193 209 225 241 257 273 289 305 321 337
2 2 18 34 50 66 82 98 114 130 146 162 178 194 210 226 242 258 274 290 306 322 338
3 3 19 35 51 67 83 99 115 131 147 163 179 195 211 227 243 259 275 291 307 323 339
4 4 20 36 52 68 84 100 116 132 148 164 180 196 212 228 244 260 276 292 308 324 340
5 5 21 37 53 69 85 101 117 133 149 165 181 197 213 229 245 261 277 293 309 325 341
6 6 22 38 54 70 86 102 118 134 150 166 182 198 214 230 246 262 278 294 310 326 342
7 7 23 39 55 71 87 103 119 135 151 167 183 199 215 231 247 263 279 295 311 327 343
8 8 24 40 56 72 88 104 120 136 152 168 184 200 216 232 248 264 280 296 312 328 344
9 9 25 41 57 73 89 105 121 137 153 169 185 201 217 233 249 265 281 297 313 329 345
10 10 26 42 58 74 90 106 122 138 154 170 186 202 218 234 250 266 282 298 314 330 346
11 11 27 43 59 75 91 107 123 139 155 171 187 203 219 235 251 267 283 299 315 331 347
12 12 28 44 60 76 92 108 124 140 156 172 188 204 220 236 252 268 284 300 316 332 348
13 13 29 45 61 77 93 109 125 141 157 173 189 205 221 237 253 269 285 301 317 333 349
14 14 30 46 62 78 94 110 126 142 158 174 190 206 222 238 254 270 286 302 318 334 350
15 15 31 47 63 79 95 111 127 143 159 175 191 207 223 239 255 271 287 303 319 335 351
16 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 256 272 288 304 320 336 352
The remaining 999 are exactly the same. Now focusing on your question:
- List 1: this consists of the values of column 1 and row 1 of all the replicas.
- List two: this consists of the values of column 1 and row 2
- Lists three: columns 1 row 3
- etc.
One possible way is this:
lista.nueva <- split(as.vector(unlist(lapply(mdresult, '[[', 1))), rep(1:16, 1000))
- With
as.vector(unlist(lapply(mdresult, '[[', 1)))
we do: (a) We cut from all data.frame
of the list, the first column, (b) we convert everything to a single vector , we end up with something like this: <col1-fila1><col1-fila2>..<col1-fila1000>
- Finally, with
rep(1:16, 1000)
we generate a "mask" for clipping by split()
, which ends up leaving us with a list of 1000 vectors, each with the full column 1 of each row of the original list.
If we see, for example, the first element of the initial list, we can see that it is composed of an element from column 1 of each of the replicas
lista.nueva[[1]]
[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[44] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[87] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[130] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[173] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[216] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[259] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1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