[R] splitting matrices

arun smartpink111 at yahoo.com
Fri Jan 4 04:05:20 CET 2013


Hi Elisa,

If the total number of elements in each of the list elements/372 are integer values, then 
set.seed(24)
l1<-lapply(c(4,5,8,10),function(i) as.data.frame(matrix(sample(1:50,40,replace=TRUE),ncol=i)))
lapply(l1,function(x) matrix(as.vector(as.matrix(x)),nrow=5))

#in your case:

lapply(mls,function(x) matrix(as.vector(as.matrix(x)),nrow=372))
A.K.









________________________________
From: eliza botto <eliza_botto at hotmail.com>
To: "smartpink111 at yahoo.com" <smartpink111 at yahoo.com> 
Sent: Thursday, January 3, 2013 8:31 PM
Subject: RE: [R] splitting matrices



Actually, you will see that 465 elements are there in 12 columns. which means total number of elements are 465*12=5580. now if you accommodate these number of elements in 372 rows, R should automatically make 5580/372=15 columns.

i hope i am clear.
thanks once again

elisa


> Date: Thu, 3 Jan 2013 17:22:42 -0800
> From: smartpink111 at yahoo.com
> Subject: Re: [R] splitting matrices
> To: eliza_botto at hotmail.com
> 
> HI Elisa,
> 
> So, you selected the nrows based on the list element with the least number of rows.  But, you also have list elements with 465 rows, i.e. not a multiple of 372 row.  IN that case, wouldn't it end up with less number of rows than 372.  Same applies for the last matrix in all the list elements.
> Arun
> 
> 
> 
> 
> 
> 
> 
> ________________________________
> From: eliza botto <eliza_botto at hotmail.com>
> To: "smartpink111 at yahoo.com" <smartpink111 at yahoo.com> 
> Sent: Thursday, January 3, 2013 8:17 PM
> Subject: RE: [R] splitting matrices
> 
> 
> 
> Dear Arun,
> thanks for replying. i actually want to convert each data frame to a matrix. so in total i want to have 16 matrices. i want to split them is such a way that each matrix should have 372 rows and the number of column which could accommodate the data.
> like in first data frame there are 1085 elements in each 12 columns. so, there are 13020 elements. i want to convert it into the matrix on the basis of 372 rows,  automatically columns will be 35.
> similarly, all the data frames should be converted to matrices on the basis of 372 rows.
> 
> i am doing it to manage some hostipal data.
> thanks in advance..
> elisa
> 
> 
> > Date: Thu, 3 Jan 2013 17:06:35 -0800
> > From: smartpink111 at yahoo.com
> > Subject: Re: [R] splitting matrices
> > To: eliza_botto at hotmail.com
> > 
> > Hi Elisa,
> > 
> > 
> > The list elements are of different dimensions.  Also, some of them have odd number of rows.  Do you wanted to split each list elements into 36 matrices or with 31 rows each?  Also, just for curiosity, is this for some specific purpose?.    
> > 
> > Arun
> > 
> > 
> > 
> > 
> > 
> > ________________________________
> > From: eliza botto <eliza_botto at hotmail.com>
> > To: "smartpink111 at yahoo.com" <smartpink111 at yahoo.com> 
> > Sent: Thursday, January 3, 2013 6:45 PM
> > Subject: RE: [R] splitting matrices
> > 
> > 
> > 
> > >res1<-lapply(split(as.data.frame(mat1),rep(1:36,each=31)),as.matrix)
> > dear arun,
> > thanks for your reply. now i was wondering that if want to apply the same command on list of 16 data frame. what change in the code do i have to make in the codes as in the present case each data frame has different dimensions?? thanks in advance...
> > the structure of my data is
> > > str(mls)
> > List of 16
> >  $ :'data.frame':       1085 obs. of  12 variables:
> >   ..$ Col1 : num [1:1085] 430 427 430 422 413 416 399 396 408 408 ...
> >   ..$ Col2 : num [1:1085] 413 410 410 410 410 408 405 405 396 382 ...
> >   ..$ Col3 : num [1:1085] 444 430 441 473 481 521 526 518 541 538 ...
> >   ..$ Col4 : num [1:1085] 676 659 659 657 659 693 750 832 897 993 ...
> >   ..$ Col5 : num [1:1085] 758 741 747 758 843 ...
> >   ..$ Col6 : num [1:1085] 3962 4387 4500 4387 3877 ...
> >   ..$ Col7 : num [1:1085] 5094 5207 5603 6169 6509 ...
> >   ..$ Col8 : num [1:1085] 5009 5377 6311 7386 8292 ...
> >   ..$ Col9 : num [1:1085] 4443 4443 4415 4160 4103 ...
> >   ..$ Col10: num [1:1085] 1556 1551 1525 1460 1409 ...
> >   ..$ Col11: num [1:1085] 852 821 812 798 784 784 781 773 770 764 ...
> >   ..$ Col12: num [1:1085] 569 572 569 563 558 552 549 543 538 532 ...
> >  $ :'data.frame':       1147 obs. of  12 variables:
> >   ..$ Col1 : num [1:1147] 45 41.9 40.5 38.8 37.7 37.1 36.8 36.5 36.2 35.7 ...
> >   ..$ Col2 : num [1:1147] 53.8 51 47 52.7 47 47 43.6 42.2 40.2 37.9 ...
> >   ..$ Col3 : num [1:1147] 36.2 36.2 36.2 36.2 36.2 35.7 34.3 34.3 34.3 36.2 ...
> >   ..$ Col4 : num [1:1147] 73.9 90 133 282 197 127 98.8 91.7 84.4 163 ...
> >   ..$ Col5 : num [1:1147] 199 199 225 233 243 252 262 277 297 297 ...
> >   ..$ Col6 : num [1:1147] 399 405 459 496 490 530 544 555 538 552 ...
> >   ..$ Col7 : num [1:1147] 496 422 391 416 411 456 453 442 430 428 ...
> >   ..$ Col8 : num [1:1147] 374 394 331 331 297 265 238 240 248 294 ...
> >   ..$ Col9 : num [1:1147] 242 309 260 247 238 225 207 320 360 274 ...
> >   ..$ Col10: num [1:1147] 129 119 113 108 97.7 97.7 91.7 88.1 85.2 84.4 ...
> >   ..$ Col11: num [1:1147] 53.2 50.4 47.6 48.1 47 44.7 43.6 43 41.9 41.1 ...
> >   ..$ Col12: num [1:1147] 46.4 46.2 46.2 45 45.6 43.6 43.6 43.6 43.6 42.8 ...
> >  $ :'data.frame':       1085 obs. of  12 variables:
> >   ..$ Col1 : num [1:1085] 68.2 68.8 69.4 69.9 69.9 70.2 68.2 66.8 65.4 64 ...
> >   ..$ Col2 : num [1:1085] 57.8 57.8 57.8 57.8 57.8 57.8 57.8 57.8 57.8 57.8 ...
> >   ..$ Col3 : num [1:1085] 54.4 54.4 54.9 55.5 55.8 56.6 57.2 57.8 58 59 ...
> >   ..$ Col4 : num [1:1085] 69.9 70.8 72.5 73.3 75 77 77.6 79 79.6 81 ...
> >   ..$ Col5 : num [1:1085] 99.7 102 103 105 106 108 110 112 114 115 ...
> >   ..$ Col6 : num [1:1085] 92.3 102 111 118 124 133 140 150 145 144 ...
> >   ..$ Col7 : num [1:1085] 462 470 479 487 493 496 487 501 507 515 ...
> >   ..$ Col8 : num [1:1085] 345 348 360 368 382 394 391 413 442 481 ...
> >   ..$ Col9 : num [1:1085] 504 473 445 422 411 391 377 362 351 351 ...
> >   ..$ Col10: num [1:1085] 161 159 156 155 151 149 148 143 142 140 ...
> >   ..$ Col11: num [1:1085] 102 100 99.7 98.5 98.5 98.5 98 98.5 97.1 96 ...
> >   ..$ Col12: num [1:1085] 85.2 84.7 84.1 83.5 83.5 82.7 82.4 82.1 81.8 81.6 ...
> >  $ :'data.frame':       558 obs. of  12 variables:
> >   ..$ Col1 : num [1:558] 1000 965 951 958 947 ...
> >   ..$ Col2 : num [1:558] 915 915 880 837 873 ...
> >   ..$ Col3 : num [1:558] 855 852 852 852 845 ...
> >   ..$ Col4 : num [1:558] 1099 1120 1382 1201 1230 ...
> >   ..$ Col5 : num [1:558] 3491 3781 3746 3081 3389 ...
> >   ..$ Col6 : num [1:558] 11484 10707 11413 10989 11590 ...
> >   ..$ Col7 : num [1:558] 11413 12686 11484 8551 7244 ...
> >   ..$ Col8 : num [1:558] 9576 10813 10283 10389 9929 ...
> >   ..$ Col9 : num [1:558] 4382 3710 3491 3261 3219 ...
> >   ..$ Col10: num [1:558] 1721 1611 1569 1509 1530 ...
> >   ..$ Col11: num [1:558] 1191 1170 1170 1141 1148 ...
> >   ..$ Col12: num [1:558] 912 922 905 898 880 ...
> >  $ :'data.frame':       1147 obs. of  12 variables:
> >   ..$ Col1 : num [1:1147] 79 79 79 81.2 79.8 79.8 78.4 77.3 77.3 73.6 ...
> >   ..$ Col2 : num [1:1147] 69.1 71.9 72.4 69.9 69.1 71.3 69.1 67.4 67.4 67.6 ...
> >   ..$ Col3 : num [1:1147] 64 62.3 63.1 62.3 60.6 59.7 60.6 62.3 60 60.3 ...
> >   ..$ Col4 : num [1:1147] 57.2 56.6 56.3 54.6 56.6 58.3 56.3 56.3 56.3 55.8 ...
> >   ..$ Col5 : num [1:1147] 75 78.4 98.2 122 104 87.2 81.8 74.7 73.9 78.4 ...
> >   ..$ Col6 : num [1:1147] 368 396 524 563 628 ...
> >   ..$ Col7 : num [1:1147] 1500 1656 1616 1695 1777 ...
> >   ..$ Col8 : num [1:1147] 843 852 767 753 730 ...
> >   ..$ Col9 : num [1:1147] 730 713 634 552 484 439 416 388 362 354 ...
> >   ..$ Col10: num [1:1147] 205 199 199 200 200 200 200 186 179 183 ...
> >   ..$ Col11: num [1:1147] 105 100 93.1 98.2 105 93.7 99.9 99.3 96.8 102 ...
> >   ..$ Col12: num [1:1147] 73.3 74.7 69.6 71.9 73 70.5 68.2 68.2 68.5 68.8 ...
> >  $ :'data.frame':       1023 obs. of  12 variables:
> >   ..$ Col1 : num [1:1023] 233 230 228 225 224 227 224 227 222 223 ...
> >   ..$ Col2 : num [1:1023] 200 199 200 200 194 194 189 192 194 193 ...
> >   ..$ Col3 : num [1:1023] 193 193 183 187 188 186 190 198 195 192 ...
> >   ..$ Col4 : num [1:1023] 198 201 202 197 197 203 212 220 225 228 ...
> >   ..$ Col5 : num [1:1023] 306 306 331 342 331 331 345 328 323 311 ...
> >   ..$ Col6 : num [1:1023] 1449 1593 1692 1735 1551 ...
> >   ..$ Col7 : num [1:1023] 3000 3085 2972 2790 2451 ...
> >   ..$ Col8 : num [1:1023] 2301 2338 2465 2626 2745 ...
> >   ..$ Col9 : num [1:1023] 2643 2666 2663 2725 2765 ...
> >   ..$ Col10: num [1:1023] 600 600 617 625 631 640 628 611 580 558 ...
> >   ..$ Col11: num [1:1023] 379 368 359 357 354 351 351 348 342 337 ...
> >   ..$ Col12: num [1:1023] 262 262 260 257 253 251 251 250 249 249 ...
> >  $ :'data.frame':       1147 obs. of  12 variables:
> >   ..$ Col1 : num [1:1147] 15.3 15.3 15.3 15.3 14.2 14.2 14.2 14.2 14.2 15.3 ...
> >   ..$ Col2 : num [1:1147] 13 13 12 12 12 11.2 11.2 11.2 11.2 10.5 ...
> >   ..$ Col3 : num [1:1147] 11.2 11.2 11.2 11.2 11.2 11.2 12 12 12 12 ...
> >   ..$ Col4 : num [1:1147] 16.6 17 17.3 18 18 18 19.4 19.4 19.4 19.4 ...
> >   ..$ Col5 : num [1:1147] 72.5 81.8 84.9 95.7 101 113 108 112 122 133 ...
> >   ..$ Col6 : num [1:1147] 201 225 253 273 286 283 286 273 281 273 ...
> >   ..$ Col7 : num [1:1147] 276 273 261 265 261 283 283 286 281 253 ...
> >   ..$ Col8 : num [1:1147] 239 234 226 213 202 178 180 178 194 206 ...
> >   ..$ Col9 : num [1:1147] 165 160 159 153 149 145 145 164 168 137 ...
> >   ..$ Col10: num [1:1147] 95.1 92.3 86.1 73.1 72.5 69.4 68 62.3 60 54.6 ...
> >   ..$ Col11: num [1:1147] 30 30 28.3 27.5 27.7 26.9 28.1 27.3 27.5 26.7 ...
> >   ..$ Col12: num [1:1147] 21.3 21.3 21.3 21.3 21.3 20.5 20.5 20.5 20.5 20.5 ...
> >  $ :'data.frame':       713 obs. of  12 variables:
> >   ..$ Col1 : num [1:713] 6.43 5.83 4.81 4.67 4.67 4.81 4.87 4.87 4.62 4.36 ...
> >   ..$ Col2 : num [1:713] 4.02 3.85 3.91 3.96 5.01 4.42 4.93 5.07 5.21 5.58 ...
> >   ..$ Col3 : num [1:713] 16.5 13.9 33.1 52.7 48.7 25.2 21.6 18 16.3 15.7 ...
> >   ..$ Col4 : num [1:713] 45.3 56.3 52.1 51.3 51.3 58.3 52.4 44.5 39.1 35.4 ...
> >   ..$ Col5 : num [1:713] 38.2 36.2 37.1 39.1 41.6 32.6 30.9 28.9 27.7 30.3 ...
> >   ..$ Col6 : num [1:713] 24.6 23.6 25.9 30.3 23.4 23.2 23.6 20.2 22.2 19.2 ...
> >   ..$ Col7 : num [1:713] 14.9 15.7 14.2 31.4 25.2 37.1 15.5 18 15.2 14.2 ...
> >   ..$ Col8 : num [1:713] 17.4 16.6 18.3 63.7 60.9 36.8 30.3 23.2 20.2 17.8 ...
> >   ..$ Col9 : num [1:713] 19.5 18.9 19.2 17.2 25.2 33.7 27.5 23.4 20.4 26.1 ...
> >   ..$ Col10: num [1:713] 13.5 10.4 10.2 10.3 9.71 9.26 8.92 9.03 9.37 9.6 ...
> >   ..$ Col11: num [1:713] 6.26 6.17 6.09 6 5.83 6.09 20.2 7.76 6.43 6.26 ...
> >   ..$ Col12: num [1:713] 5.15 4.93 4.93 4.87 5.66 5.66 5.21 4.93 4.87 4.62 ...
> >  $ :'data.frame':       372 obs. of  12 variables:
> >   ..$ Col1 : num [1:372] 942 928 925 928 942 ...
> >   ..$ Col2 : num [1:372] 917 914 923 940 931 ...
> >   ..$ Col3 : num [1:372] 1633 1636 1373 1322 1387 ...
> >   ..$ Col4 : num [1:372] 1429 1180 1268 1180 1129 ...
> >   ..$ Col5 : num [1:372] 1466 2239 2236 2173 2258 ...
> >   ..$ Col6 : num [1:372] 4358 4245 4188 4302 4613 ...
> >   ..$ Col7 : num [1:372] 5292 5037 5094 4670 4132 ...
> >   ..$ Col8 : num [1:372] 2776 2323 2561 2479 2496 ...
> >   ..$ Col9 : num [1:372] 2434 3453 2264 2570 2476 ...
> >   ..$ Col10: num [1:372] 3594 3085 3056 2858 3453 ...
> >   ..$ Col11: num [1:372] 1367 1305 1344 1500 1438 ...
> >   ..$ Col12: num [1:372] 1769 1613 1633 1500 1523 ...
> >  $ :'data.frame':       1116 obs. of  12 variables:
> >   ..$ Col1 : num [1:1116] 326 340 294 294 317 ...
> >   ..$ Col2 : num [1:1116] 690 362 436 453 376 ...
> >   ..$ Col3 : num [1:1116] 196 172 191 136 164 ...
> >   ..$ Col4 : num [1:1116] 379 419 620 948 1254 ...
> >   ..$ Col5 : num [1:1116] 1180 1180 1211 1364 1562 ...
> >   ..$ Col6 : num [1:1116] 1429 1384 2224 2513 2751 ...
> >   ..$ Col7 : num [1:1116] 2383 2408 2360 2272 2332 ...
> >   ..$ Col8 : num [1:1116] 1984 1998 1902 1789 1574 ...
> >   ..$ Col9 : num [1:1116] 1095 1115 1214 1143 1194 ...
> >   ..$ Col10: num [1:1116] 580 552 495 501 467 ...
> >   ..$ Col11: num [1:1116] 300 300 297 294 294 ...
> >   ..$ Col12: num [1:1116] 323 300 289 314 320 ...
> >  $ :'data.frame':       1085 obs. of  12 variables:
> >   ..$ Col1 : num [1:1085] 396 396 396 396 396 ...
> >   ..$ Col2 : num [1:1085] 379 371 371 371 371 ...
> >   ..$ Col3 : num [1:1085] 354 354 345 345 354 ...
> >   ..$ Col4 : num [1:1085] 354 354 362 362 362 ...
> >   ..$ Col5 : num [1:1085] 492 447 561 527 527 ...
> >   ..$ Col6 : num [1:1085] 1155 1334 1002 849 832 ...
> >   ..$ Col7 : num [1:1085] 3283 2888 2648 2662 2803 ...
> >   ..$ Col8 : num [1:1085] 5603 5663 5607 5578 5635 ...
> >   ..$ Col9 : num [1:1085] 3594 3313 2973 2662 2662 ...
> >   ..$ Col10: num [1:1085] 1053 1019 1002 951 917 ...
> >   ..$ Col11: num [1:1085] 515 501 493 481 479 470 462 459 447 447 ...
> >   ..$ Col12: num [1:1085] 405 402 396 396 388 379 379 377 371 365 ...
> >  $ :'data.frame':       620 obs. of  12 variables:
> >   ..$ Col1 : num [1:620] NA NA NA NA NA NA NA NA NA NA ...
> >   ..$ Col2 : num [1:620] NA NA NA NA NA NA NA NA NA NA ...
> >   ..$ Col3 : num [1:620] NA NA NA NA NA NA NA NA NA NA ...
> >   ..$ Col4 : num [1:620] NA NA NA NA NA NA NA NA NA NA ...
> >   ..$ Col5 : num [1:620] NA NA NA NA NA NA NA NA NA NA ...
> >   ..$ Col6 : num [1:620] NA NA NA NA NA NA NA NA NA NA ...
> >   ..$ Col7 : num [1:620] NA NA NA NA NA NA NA NA NA NA ...
> >   ..$ Col8 : num [1:620] NA NA NA NA NA NA NA NA NA NA ...
> >   ..$ Col9 : num [1:620] 6311 6452 6396 6169 5717 ...
> >   ..$ Col10: num [1:620] 1695 1610 1568 1506 1407 ...
> >   ..$ Col11: num [1:620] 645 640 634 628 617 ...
> >   ..$ Col12: num [1:620] 470 464 461 456 453 ...
> >  $ :'data.frame':       620 obs. of  12 variables:
> >   ..$ Col1 : num [1:620] NA NA NA NA NA NA NA NA NA NA ...
> >   ..$ Col2 : num [1:620] NA NA NA NA NA NA NA NA NA NA ...
> >   ..$ Col3 : num [1:620] NA NA NA NA NA NA NA NA NA NA ...
> >   ..$ Col4 : num [1:620] NA NA NA NA NA NA NA NA NA NA ...
> >   ..$ Col5 : num [1:620] 168 190 218 246 320 ...
> >   ..$ Col6 : num [1:620] 458 391 362 331 450 ...
> >   ..$ Col7 : num [1:620] 1036 1092 1098 968 1044 ...
> >   ..$ Col8 : num [1:620] 1327 1344 1271 1276 1322 ...
> >   ..$ Col9 : num [1:620] 492 439 416 461 515 555 543 566 543 577 ...
> >   ..$ Col10: num [1:620] 171 171 160 153 153 153 153 153 153 153 ...
> >   ..$ Col11: num [1:620] 139 135 135 135 135 135 132 132 130 130 ...
> >   ..$ Col12: num [1:620] 99.6 99.6 99.6 99.6 99.6 99.6 99.6 99.6 99.6 99.3 ...
> >  $ :'data.frame':       465 obs. of  12 variables:
> >   ..$ Col1 : num [1:465] 29.4 29.4 28.9 29.7 30.6 ...
> >   ..$ Col2 : num [1:465] 29.1 29.4 28.9 28 28 27.5 27.5 27.5 27.5 27.5 ...
> >   ..$ Col3 : num [1:465] 30.6 31.1 30.3 30.3 31.1 30.3 30.6 30.6 29.7 31.1 ...
> >   ..$ Col4 : num [1:465] 27.1 26.6 24.8 22.1 26.6 26.6 26.6 26.6 26.6 26.6 ...
> >   ..$ Col5 : num [1:465] 45.3 46.4 46.4 47.5 50.4 51.5 53.2 53.2 54.3 55.5 ...
> >   ..$ Col6 : num [1:465] 137 145 150 161 168 172 180 183 187 220 ...
> >   ..$ Col7 : num [1:465] 226 212 195 187 173 ...
> >   ..$ Col8 : num [1:465] 337 504 583 405 376 ...
> >   ..$ Col9 : num [1:465] 388 359 359 357 334 ...
> >   ..$ Col10: num [1:465] 129 126 122 111 109 103 100 97.1 93.7 91.1 ...
> >   ..$ Col11: num [1:465] 43.6 38.5 40.2 47.5 44.1 41.9 39.1 38.5 36.8 36.2 ...
> >   ..$ Col12: num [1:465] 28.3 27.1 26.1 26.6 26.6 25.7 25.2 26.6 26.6 26.1 ...
> >  $ :'data.frame':       899 obs. of  12 variables:
> >   ..$ Col1 : num [1:899] 47.5 48.7 49.8 49.2 48.4 49.2 49.8 51.5 48.7 49.8 ...
> >   ..$ Col2 : num [1:899] 43.9 44.7 50.4 50.4 43.9 43 42.4 44.7 44.1 45 ...
> >   ..$ Col3 : num [1:899] 38.2 38.2 38.8 37.4 37.1 38.2 38.2 37.4 37.1 37.9 ...
> >   ..$ Col4 : num [1:899] 38.2 37.9 38.2 39.1 38.8 38.5 38.8 39.1 39.1 39.1 ...
> >   ..$ Col5 : num [1:899] 64 79.8 90.6 99 99.3 106 96.5 93.4 82.9 77 ...
> >   ..$ Col6 : num [1:899] 118 130 169 212 248 294 334 393 439 473 ...
> >   ..$ Col7 : num [1:899] 1223 1347 1469 1548 1593 ...
> >   ..$ Col8 : num [1:899] 1237 1279 1463 1582 1808 ...
> >   ..$ Col9 : num [1:899] 1423 1401 1211 1022 792 ...
> >   ..$ Col10: num [1:899] 291 258 226 196 178 194 192 174 168 162 ...
> >   ..$ Col11: num [1:899] 119 118 114 112 108 107 106 105 104 99.9 ...
> >   ..$ Col12: num [1:899] 82.4 82.1 81.8 81.5 81.2 80.9 80.7 80.4 80.1 79.2 ...
> >  $ :'data.frame':       1147 obs. of  12 variables:
> >   ..$ Col1 : num [1:1147] 128 128 128 128 122 ...
> >   ..$ Col2 : num [1:1147] 105.3 105.3 105.3 99.9 99.9 ...
> >   ..$ Col3 : num [1:1147] 94.5 94.5 94.5 94.5 94.5 ...
> >   ..$ Col4 : num [1:1147] 89.4 89.4 89.4 89.4 89.4 ...
> >   ..$ Col5 : num [1:1147] 134 140 152 158 177 ...
> >   ..$ Col6 : num [1:1147] 340 439 450 470 640 ...
> >   ..$ Col7 : num [1:1147] 3538 4217 2258 1919 1845 ...
> >   ..$ Col8 : num [1:1147] 3198 3226 3226 3254 3283 ...
> >   ..$ Col9 : num [1:1147] 1910 2012 1885 1910 1882 ...
> >   ..$ Col10: num [1:1147] 498 580 563 563 546 ...
> >   ..$ Col11: num [1:1147] 252 243 243 227 227 ...
> >   ..$ Col12: num [1:1147] 165 165 165 165 165 ...
> > 
> > 
> > 
> > > Date: Thu, 3 Jan 2013 09:12:11 -0800
> > > From: smartpink111 at yahoo.com
> > > Subject: Re: [R] splitting matrices
> > > To: macqueen1 at llnl.gov
> > > CC: eliza_botto at hotmail.com; r-help at r-project.org
> > > 
> > > Hi,
> > > You could also try:
> > > set.seed(51)
> > > mat1<-matrix(sample(1:5000,1116*12,replace=TRUE),nrow=1116)
> > >  dim(mat1)
> > > #[1] 1116   12
> > > 
> > > res1<-lapply(split(as.data.frame(mat1),rep(1:36,each=31)),as.matrix)
> > >  unlist(lapply(res1,nrow))
> > > # 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 
> > > #31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 
> > > #27 28 29 30 31 32 33 34 35 36 
> > > #31 31 31 31 31 31 31 31 31 31 
> > > 
> > > A.K.
> > > 
> > > 
> > > 
> > > 
> > > ----- Original Message -----
> > > From: "MacQueen, Don" <macqueen1 at llnl.gov>
> > > To: eliza botto <eliza_botto at hotmail.com>; "r-help at r-project.org" <r-help at r-project.org>
> > > Cc: 
> > > Sent: Thursday, January 3, 2013 11:56 AM
> > > Subject: Re: [R] splitting matrices
> > > 
> > > This example illustrates a method that may do what you want.
> > > 
> > > ## split a 20x5 matrix into five 4x5 matrices
> > > xmat <- matrix(1:100, nrow=20, ncol=5, byrow=TRUE)
> > > xsplit <- rep( 1:5, times= rep(4,5))
> > > tmp <- split.data.frame(xmat,xsplit)
> > > 
> > > You will need to change xsplit to fit your dimensions.
> > > 
> > > -Don
> > > 
> > > 
> > > -- 
> > > Don MacQueen
> > > 
> > > Lawrence Livermore National Laboratory
> > > 7000 East Ave., L-627
> > > Livermore, CA 94550
> > > 925-423-1062
> > > 
> > > 
> > > 
> > > 
> > > 
> > > On 1/3/13 8:40 AM, "eliza botto" <eliza_botto at hotmail.com> wrote:
> > > 
> > > >
> > > >
> > > >Dear useRs,
> > > >i want to split a matrix having 1116rows and 12 columns. i want to split
> > > >that matrix into 36 small matrices each having 12 columns and 31 rows.
> > > >The big matrix should be splitted row wise. which means that the first
> > > >small matrix should copy values which are in first 31 rows and 12 columns
> > > >of the big matrix. similarly 2nd small matrix should contain values from
> > > >32nd to 63rd row of the big matrix and so on. on the whole i want to have
> > > >36 small matrices.i tried
> > > >dim(dd) <- c(31,12,35)
> > > >but the result are not stisfactory...
> > > >thanks in advance
> > > >elisa                           
> > > >    [[alternative HTML version deleted]]
> > > >
> > > >______________________________________________
> > > >R-help at r-project.org mailing list
> > > >https://stat.ethz.ch/mailman/listinfo/r-help
> > > >PLEASE do read the posting guide
> > > >http://www.R-project.org/posting-guide.html
> > > >and provide commented, minimal, self-contained, reproducible code.
> > > 
> > > ______________________________________________
> > > R-help at r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> > >




More information about the R-help mailing list