Re: [R] Subseting in a 3D array

2003-10-15 Thread Prof Brian Ripley
That does use a for loop inside apply.

I would make use of dim shuffling: you have an array indexed by (x,y,z)
and you want (I presume) a matrix indexed by ((x,y), z) for specified
pairs (x,y).

X <- ib5km15.dbc
dim(X) <- c(190*241, 19)
X[ib5km.lincol.random %*% c(1, 240) - 240, ]

should be something close to what you want if I have read the runes 
correctly.


On Wed, 15 Oct 2003, Tony Plate wrote:

> One way would be:
> 
>  > apply(ib5km.lincol.random[1:3,], 1, function(i) ib5km15.dbc[i[1],i[2],])
> 
> (untested)
> 
> -- Tony Plate
> 
> At Wednesday 06:47 PM 10/15/2003 +0200, Agustin Lobo wrote:
> 
> >Hi!
> >
> >I have a 3d array:
> > > dim(ib5km15.dbc)
> >[1] 190 241  19
> >
> >and a set of positions to extract:
> > > ib5km.lincol.random[1:3,]
> >  [,1] [,2]
> >[1,]   78   70
> >[2,]   29  213
> >[3,]  180   22
> >
> >Geting the values of a 2D array
> >for that set of positions would
> >be:
> >
> > > ima <- ib5km15.dbc[,,1]
> > > ima[ib5km.lincol.random[1:10,]]
> >
> >but don't find the way for the case
> >of the 3D array:
> >
> > > ib5km15.dbc[ib5km.lincol.random[1:10,],]
> >Error in ib5km15.dbc[ib5km.lincol.random[1:10, ], ] :
> > incorrect number of dimensions
> >
> >Could anyone suggest the way of subseting
> >the 3D array to get a vector of z values
> >for each position recorded in ib5km.lincol.random?
> >(avoiding the use of for loops).
> >
> >Thanks
> >
> >Agus
> >
> >Dr. Agustin Lobo
> >Instituto de Ciencias de la Tierra (CSIC)
> >Lluis Sole Sabaris s/n
> >08028 Barcelona SPAIN
> >tel 34 93409 5410
> >fax 34 93411 0012
> >[EMAIL PROTECTED]
> >
> >__
> >[EMAIL PROTECTED] mailing list
> >https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
> 

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Subseting in a 3D array

2003-10-15 Thread Tony Plate
One way would be:

> apply(ib5km.lincol.random[1:3,], 1, function(i) ib5km15.dbc[i[1],i[2],])

(untested)

-- Tony Plate

At Wednesday 06:47 PM 10/15/2003 +0200, Agustin Lobo wrote:

Hi!

I have a 3d array:
> dim(ib5km15.dbc)
[1] 190 241  19
and a set of positions to extract:
> ib5km.lincol.random[1:3,]
 [,1] [,2]
[1,]   78   70
[2,]   29  213
[3,]  180   22
Geting the values of a 2D array
for that set of positions would
be:
> ima <- ib5km15.dbc[,,1]
> ima[ib5km.lincol.random[1:10,]]
but don't find the way for the case
of the 3D array:
> ib5km15.dbc[ib5km.lincol.random[1:10,],]
Error in ib5km15.dbc[ib5km.lincol.random[1:10, ], ] :
incorrect number of dimensions
Could anyone suggest the way of subseting
the 3D array to get a vector of z values
for each position recorded in ib5km.lincol.random?
(avoiding the use of for loops).
Thanks

Agus

Dr. Agustin Lobo
Instituto de Ciencias de la Tierra (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona SPAIN
tel 34 93409 5410
fax 34 93411 0012
[EMAIL PROTECTED]
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] Subseting in a 3D array

2003-10-15 Thread Paul Lemmens
Hoi Agustin,

--On woensdag 15 oktober 2003 18:47 +0200 Agustin Lobo <[EMAIL PROTECTED]> 
wrote:

Could anyone suggest the way of subseting
the 3D array to get a vector of z values
for each position recorded in ib5km.lincol.random?
(avoiding the use of for loops).
Is section 5.3 from the Introduction to R (p21) helpfull?

regards,
Paul
--
Paul Lemmens
NICI, University of Nijmegen  ASCII Ribbon Campaign /"\
Montessorilaan 3 (B.01.03)Against HTML Mail \ /
NL-6525 HR Nijmegen  X
The Netherlands / \
Phonenumber+31-24-3612648
Fax+31-24-3616066
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help