[R] spinning and flipping arrays
Bill Rising
brising at louisville.edu
Mon May 26 21:13:01 CEST 2003
On 5/26/2003 15:05, Spencer Graves wrote
> I know of no single function to do this; perhaps someone else does.
> I don't have time to write and debug functions to do this myself, but
>it should be easy enough to write functions like the following:
>
>flip3 <-
>function(x){
> n3 <- dim(x)[3]
> x[,,n3:1]
>}
>spin3 <-
>function(x, k=1){
> n3 <- dim(x)[3]
> x[,,1+(((1+k):(n3+k))%%n3)]
>}
These are pretty much what I'd figured out...
>
>With a little more work, I could generate functions that would do this
>for any dimension of arrays with any number of dimensions. To do that,
>I might have to compute S-Plus commands using "cmd <- paste(...)" and
>then execute them using "eval(parse(text=cmd))".
This last piece is what I think I needed. I had been trying to just put
the
/argument/ to the "[" command together, instead of putting together the
entire command.
Thanks for the tip. I'll keep working on it.
Bill
More information about the R-help
mailing list