Re: [R] How to manipulate an abitrary dimensioned array.

From: Berton Gunter <gunter.berton_at_gene.com>
Date: Fri 28 Oct 2005 - 09:11:55 EST


Not sure what you're after, but the kth dimension of an array y can be obtained as:
apply(y,k,c). Each column of the resulting matrix can then be dimensioned, if you like, via dim(y)[-k] .

"The business of the statistician is to catalyze the scientific learning process." - George E. P. Box    

> -----Original Message-----
> From: Mike Meyer [mailto:mikem@salter-point.com]
> Sent: Thursday, October 27, 2005 3:43 PM
> To: Berton Gunter
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] How to manipulate an abitrary dimensioned array.
>
> Thanks for the suggestion.
> Perhaps I can see how to use apply to get the ratio, but say
> I also want
> to return X[,,,,1] in a general way. Maybe I am being dense
> but I just

> don't see it --- probably as a result of too much Perl/Python/Java
> recently that is clouding my mind.
>
> So can someone suggest a general function that will give me the last
> layer of an arbitrary dimensioned array?
>
> Berton Gunter wrote:
> > Why doesn't apply() already do what you want?
> >
> > -- Bert Gunter
> > Genentech Non-Clinical Statistics
> > South San Francisco, CA
> >
> > "The business of the statistician is to catalyze the
> scientific learning
> > process." - George E. P. Box
> >
> >
> >
> >
> >>-----Original Message-----
> >>From: r-help-bounces@stat.math.ethz.ch
> >>[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Mike Meyer
> >>Sent: Thursday, October 27, 2005 2:50 PM
> >>To: r-help@stat.math.ethz.ch
> >>Subject: [R] How to manipulate an abitrary dimensioned array.
> >>
> >>If I have an n1 x n1 x 2 array X I can calculate, say,
> >>X[,,1]/X[,,2].
> >>
> >>If it is a 4 dimensional array then I want to be able to calculate
> >>X[,,,1]/X[,,,2], and similarly for higher dimensions.
> >>
> >>How can I write a function to do this in a general way
> >>without having to
> >>do a switch for each possible length(dim(X)). So I want a
> function g
> >>that will take an arbitrary dimensioned array, X, and return
> >>X[,,,1]/X[,,,2], etc. I know how to do this by turning X into a
> >>vector, then doing the division, then re-shaping as an array,
> >>but that
> >>doesn't seem very elegant.
> >>
> >>What I think I am missing is how to paste/substitute/eval a
> bunch of
> >>commas into an array selection.
> >>
> >>Thanks, --Mike
> >>
> >>--
> >>Mike Meyer, Seattle WA
> >>
> >>______________________________________________
> >>R-help@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
> >>
> >
> >
> > ______________________________________________
> > R-help@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
>
> --
>
> Mike Meyer, Seattle WA
>
>
>



R-help@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 Received on Fri Oct 28 09:22:44 2005

This archive was generated by hypermail 2.1.8 : Fri 28 Oct 2005 - 12:14:25 EST