An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121112/79be8291/attachment.pl>
Selected matrices of an array and put into a list
3 messages · Haris Rhrlp, Dimitris Rizopoulos, arun
One approach is: BB <- rnorm(6*5*27) dim(BB) <- c(6, 5, 27) lapply(2:27, function (i) BB[, , i]) I hope it helps. Best, Dimitris
On 11/12/2012 8:56 AM, Haris Rhrlp wrote:
Dear R users, I have an array that has matrices that i want BB[16,5,2:27] i want to put each of the 26 matrices into a List thanks in advance [[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.
Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/
Hi, You can also use ?alply() library(plyr) BB<-array(sample(1:500,3*5*27,replace=TRUE),dim=c(3,5,27)) res<-alply(BB,3,function(x) x)[2:27] str(res) List of 26 #$ 2 : int [1:3, 1:5] 337 476 331 481 168 111 439 151 399 430 ... # $ 3 : int [1:3, 1:5] 77 171 225 498 277 37 429 472 215 351 ... # $ 4 : int [1:3, 1:5] 243 393 274 113 266 175 210 404 450 4 ... --------------------------------------------------------------------------- -------------------------------------------------------------------------- #$ 25: int [1:3, 1:5] 319 398 351 235 280 476 81 393 30 304 ... # $ 26: int [1:3, 1:5] 153 187 63 252 17 150 22 439 320 382 ... # $ 27: int [1:3, 1:5] 282 356 75 190 364 402 499 167 481 307 ... A.K. ----- Original Message ----- From: Haris Rhrlp <haris_r_help at yahoo.com> To: "R-help at r-project.org" <R-help at r-project.org> Cc: Sent: Monday, November 12, 2012 2:56 AM Subject: [R] Selected matrices of an array and put into a list Dear R users, I have an array that has matrices that i want BB[16,5,2:27] i want to put each of the 26 matrices into a List? thanks in advance ??? [[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.