~ubuntu-branches/ubuntu/precise/r-cran-slam/precise

« back to all changes in this revision

Viewing changes to R/array.R

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2011-02-10 11:41:40 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20110210114140-juiktz2cqqhznpyn
Tags: 0.1-20-1
* New upstream release

* debian/control: Set (Build-)Depends: to current R version

Show diffs side-by-side

added added

removed removed

Lines of Context:
211
211
{
212
212
    sum(x$v) / prod(dim(x))
213
213
}
 
214
 
 
215
aperm.simple_sparse_array <-
 
216
function(a, perm = NULL, ...)
 
217
{
 
218
    s <- seq_along(a$dim)
 
219
    if(is.null(perm))
 
220
        perm <- rev(s)
 
221
    else {
 
222
        perm <- if(is.character(perm))
 
223
            match(perm, names(a$dimnames))
 
224
        else if(is.numeric(perm))
 
225
            match(perm, s)
 
226
        else NULL
 
227
        if(length(perm) != length(s) || any(is.na(perm)))
 
228
            stop("Invalid permutation.")
 
229
    }
 
230
    simple_sparse_array(a$i[, perm, drop = FALSE], a$v,
 
231
                        a$dim[perm], a$dimnames[perm])
 
232
    
 
233
}