[R] spinning and flipping arrays
Spencer Graves
spencer.graves at pdf.com
Mon May 26 22:19:27 CEST 2003
You may also be interested in "aperm", which permutes the indices of an
array. Thus, t(x) is the same as aperm(x, 2:1).
spencer graves
Bill Rising wrote:
> 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
More information about the R-help
mailing list