Displaying 3 results from an estimated 3 matches for "revdim".
Did you mean:
readim
2017 Jun 01
0
Reversing one dimension of an array, in a generalized case
??
> z <- array(1:24,dim=2:4)
> all.equal(f(z,3),f2(z,3))
[1] "Attributes: < Component ?dim?: Mean relative difference: 0.4444444 >"
[2] "Mean relative difference: 0.6109091"
In fact,
> dim(f(z,3))
[1] 2 3 4
> dim(f2(z,3))
[1] 3 4 2
Have I made some sort of stupid error here? Or have I misunderstood
what was wanted?
Cheers,
Bert
Bert Gunter
2017 Jun 01
3
Reversing one dimension of an array, in a generalized case
Here is an alternative approach using apply(). Note that with apply() you are reversing rows or columns not indices of rows or columns so apply(junk, 2, rev) reverses the values in each column not the column indices. We actually need to use rev() on everything but the index we are interested in reversing:
f2 <- function(a, wh) {
dims <- seq_len(length(dim(a)))
dims <-
2017 Jun 01
5
Reversing one dimension of an array, in a generalized case
Hi All:
I have been looking for an elegant way to do the following, but haven't found it, I have never had a good understanding of any of the "apply" functions.
A simplified idea is I have an array, say:
junk(5, 10, 3)
where (5, 10, 3) give the dimension sizes, and I want to reverse the second dimension, so I could do:
junk1 <- junk[, rev(seq_len(10), ]
but what I am