Displaying 2 results from an estimated 2 matches for "dimnum".
Did you mean:
dignum
2010 Jul 29
1
Using 'dimname names' in aperm() and apply()
...quot;to","from") )
res <-apply( y, "to", sum)
--
This makes the array much easier to handle than having to keep track
which dimension currently means what.
For aperm and apply, the change seems very simple - one new function,
and an additional line in each.
----------
dimnum.from.dimnamename <- function(A, dimensions)
{
if( is.character(dimensions) ) {
n <- names(dimnames(A))
if( !is.null(n) ) {
dimnum <- seq( along=n)
names(dimnum) <- n
dimensions <- dimnum[dimensions]
}
}
dimensions
}
aperm <- functio...
2010 Jul 26
2
the real dimnames
...;,"to") )
This way, I don't have to remember what is the order of the dims of A.
It is easy to extend the functionality of aperm, so that the above
code works:
---
my.aperm=function( A, d , ...) {
n=names(dimnames(A))
if( is.null(n) ) {
return( aperm(A,d, ...))
}
dimnum = seq(along=n)
names(dimnum) = n
return( aperm(A, dimnum[d], ... ))
}
--
It seems some functions support these dim labels (print, for example),
and some don't (for example, matrix multiplication doesn't, aperm
doesn't, apply doesn't).
Another cool way to use these, woul...