Dimitris Rizopoulos
2005-Apr-19 12:54 UTC
[R] indexing an array using an index-array, but one entry being ', '
in the specific example you could consider something like this: test <- array(c(1:16), dim = c(3,4,3)) ## test.ind <- rbind(c(2,4,1), c(2,4,2), c(2,4,3)) test[test.ind] test[2,4,] I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Christoph Lehmann" <christoph.lehmann at gmx.ch> To: <R-help at stat.math.ethz.ch> Sent: Tuesday, April 19, 2005 3:11 PM Subject: [R] indexing an array using an index-array, but one entry being ', '> Hi > I have the following array: > > test <- array(c(1:16), dim = c(3,4,3)) > test > ## I call some enries using an index array > test.ind <- array(rbind(c(1,2,1), c(3,3,2)), dim = c(2,3)) > test[test.ind] > > ## suppose I want all values in the 2nd row and 4th col over > ## all three 3rd dimensions > test[2,4,] > > > how to specify a test.ind array with the last index left with ',' > i.e > test.ind should be evaluated as "2, 4, , " so that it can be > calledlike above as test[test.ind] and the > result should be [1] 11 7 3 > > thanks for a hint > Cheers > christoph > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
Christoph Lehmann
2005-Apr-19 13:11 UTC
[R] indexing an array using an index-array, but one entry being ', '
Hi I have the following array: test <- array(c(1:16), dim = c(3,4,3)) test ## I call some enries using an index array test.ind <- array(rbind(c(1,2,1), c(3,3,2)), dim = c(2,3)) test[test.ind] ## suppose I want all values in the 2nd row and 4th col over ## all three 3rd dimensions test[2,4,] how to specify a test.ind array with the last index left with ',' i.e test.ind should be evaluated as "2, 4, , " so that it can be calledlike above as test[test.ind] and the result should be [1] 11 7 3 thanks for a hint Cheers christoph
Christoph Lehmann
2005-Apr-19 13:48 UTC
[R] indexing an array using an index-array, but one entry being ', '
OK, the hint by Dimitris applied I just do very simple: test <- array(c(1:16), dim = c(3,4,3)) test ## I call some enries using an index array test.ind <- array(rbind(c(1,2,1), c(3,3,2)), dim = c(2,3)) test[test.ind] ## suppose I want all values in the 2nd row and 4th col over ## all three 3rd dimensions test[2,4,] ## using an index array nn <- dim(test)[3] voxel.ind <- c(2, 4) test.ind <- array(cbind(rep(voxel.ind[1], nn), rep(voxel.ind[2], nn), 1:nn), dim = c(nn, 3)) test[test.ind] cheers christoph Christoph Lehmann wrote:> Hi > I have the following array: > > test <- array(c(1:16), dim = c(3,4,3)) > test > ## I call some enries using an index array > test.ind <- array(rbind(c(1,2,1), c(3,3,2)), dim = c(2,3)) > test[test.ind] > > ## suppose I want all values in the 2nd row and 4th col over > ## all three 3rd dimensions > test[2,4,] > > > how to specify a test.ind array with the last index left with ',' i.e > test.ind should be evaluated as "2, 4, , " so that it can be > calledlike above as test[test.ind] and the > result should be [1] 11 7 3 > > thanks for a hint > Cheers > christoph > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >