...@riskspan.com
Subject: Re: [R] array slice notation?
To: r-help@r-project.org
Message-ID: 24819883.p...@talk.nabble.com
Content-Type: text/plain; charset=UTF-8
Very nice. Two questions:
1 Do you have any idea of the timing difference, if any, between this and
the vector-subscripting method?
2 How do you
...@r-project.org] P#229; vegne
af Steve Jaffe [sja...@riskspan.com]
Sendt: 5. august 2009 04:45
Til: r-help@r-project.org
Emne: Re: [R] array slice notation?
Very nice. Two questions:
1 Do you have any idea of the timing difference, if any, between this and
the vector-subscripting method?
2 How do
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
Hi,
On Aug 4, 2009, at 3:23 PM, Steve Jaffe wrote:
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
Yes, I was thinking more in terms of mental operations than physical.
I think the following works, but it doesn't seem entirely transparent :-)
Given array A, and a vector of row indices v (ie 1 = v = dim(A)[1]), the
slice of rows v is
A[ outer(v, dim(A)[1]*( 1:prod(dim(A)[-1])-1 ), '+') ]
Although you *do* have to re-assign the dimensions, otherwise the result is
just a flat vector, ie
slice - A[ outer(v, dim(A)[1]*( 1:prod(dim(A)[-1])-1 ), '+') ]
dim(slice) - dim(A)[-1]
Steve Jaffe wrote:
A[ outer(v, dim(A)[1]*( 1:prod(dim(A)[-1])-1 ), '+') ]
--
View this message in
] P#229; 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
correction -- that would work for a single row, if you want the result to be
an array with one fewer dimensions. But in general you get an array of the
same dimension you started with (where the first dimension may be length 1).
So:
dim(slice) - c(length(v), dim(arr)[-1])
Although you *do*
Hi Steve,
I had the same problem when writing the hierobarp function in plotrix.
Have a look at the source code (v2.6-4 in my copy lines 128-133) as the
solution seems to work well.
Jim
__
R-help@r-project.org mailing list
Very nice. Two questions:
1 Do you have any idea of the timing difference, if any, between this and
the vector-subscripting method?
2 How do you generalize this to select multiple rows eg with indexes given
by a vector 'v'?
Søren Højsgaard wrote:
You can do
A - HairEyeColor
do.call([,
10 matches
Mail list logo