You can do > A <- HairEyeColor > do.call("[", c(list(A),list(1,T,T))) Sex Eye Male Female Brown 32 36 Blue 11 9 Hazel 10 5 Green 3 2
Regards Søren ________________________________________ Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] På vegne af Steve Jaffe [sja...@riskspan.com] Sendt: 4. august 2009 21:23 Til: r-help@r-project.org Emne: [R] array slice notation? Suppose I have an n-diml array A and I want to extract the first "row" -- ie all elements A[1, ...] Interactively if I know 'n' I can write A[1,,,,,] with (n-1) commas. How do I do the same more generally, eg in a script? (I can think of doing this by converting A to a vector then extracting the approp elements then reshaping it to an array, but I wonder if there isn't a more straightforward approach) Thanks -- View this message in context: http://www.nabble.com/array-slice-notation--tp24814643p24814643.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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@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.