[R] array slice notation?

Søren Højsgaard Soren.Hojsgaard at agrsci.dk
Tue Aug 4 22:54:56 CEST 2009

You can do 
> A <- HairEyeColor
> do.call("[", c(list(A),list(1,T,T)))
Eye     Male Female
  Brown   32     36
  Blue    11      9
  Hazel   10      5
  Green    3      2


Fra: r-help-bounces at r-project.org [r-help-bounces at r-project.org] På vegne af Steve Jaffe [sjaffe at riskspan.com]
Sendt: 4. august 2009 21:23
Til: r-help at 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)

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 at r-project.org mailing list
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