reorder.array: Reorder an Array or Matrix

Description Usage Arguments Details Value See Also Examples

View source: R/mcf.R

Description

reorder.array reorders an array along a specified dimension according given names, indices or results of a function applied.

Usage

1
2
3
4
## S3 method for class 'array'
reorder(x,dim=1,names=NULL,indices=NULL,FUN=mean,...)
## S3 method for class 'matrix'
reorder(x,dim=1,names=NULL,indices=NULL,FUN=mean,...)

Arguments

x

An array

dim

An integer specifying the dimension along which x should be ordered.

names

A character vector

indices

A numeric vector

FUN

A function that can be used in apply(x,dim,FUN)

...

further arguments, ignored.

Details

Typical usages are

1
2
3
4
  reorder(x,dim,names)
  reorder(x,dim,indices)
  reorder(x,dim,FUN)
  

The result of rename(x,dim,names) is x reordered such that dimnames(x)[[dim]] is equal to the concatenation of those elements of names that are in dimnames(x)[[dim]] and the remaining elements of dimnames(x)[[dim]].

The result of rename(x,dim,indices) is x reordered along dim according to indices.

The result of rename(x,dim,FUN) is x reordered along dim according to order(apply(x,dim,FUN)).

Value

The reordered object x.

See Also

The default method of reorder in package stats.

Examples

1
2
3
4
5
  (M <- matrix(rnorm(n=25),5,5,dimnames=list(LETTERS[1:5],letters[1:5])))
  reorder(M,dim=1,names=c("E","A"))
  reorder(M,dim=2,indices=3:1)
  reorder(M,dim=1)
  reorder(M,dim=2)

Example output

Loading required package: lattice
Loading required package: MASS

Attaching package: 'memisc'

The following objects are masked from 'package:stats':

    contr.sum, contr.treatment, contrasts

The following object is masked from 'package:base':

    as.array

           a          b           c          d          e
A  1.4956787 -2.1806464 -2.39572986  0.3520614 -1.4237890
B  0.1551510  0.7013947 -0.15808608  0.2141887  1.4214606
C  0.8757019 -0.9390429  0.06609669 -1.4306694  2.3288836
D  2.6012038  0.1896782  2.57257207 -0.3290858 -0.7174502
E -0.4526429 -0.4537194 -0.16756315 -2.5305094  0.6259726
           a          b           c          d          e
E -0.4526429 -0.4537194 -0.16756315 -2.5305094  0.6259726
A  1.4956787 -2.1806464 -2.39572986  0.3520614 -1.4237890
B  0.1551510  0.7013947 -0.15808608  0.2141887  1.4214606
C  0.8757019 -0.9390429  0.06609669 -1.4306694  2.3288836
D  2.6012038  0.1896782  2.57257207 -0.3290858 -0.7174502
            c          b          a          d          e
A -2.39572986 -2.1806464  1.4956787  0.3520614 -1.4237890
B -0.15808608  0.7013947  0.1551510  0.2141887  1.4214606
C  0.06609669 -0.9390429  0.8757019 -1.4306694  2.3288836
D  2.57257207  0.1896782  2.6012038 -0.3290858 -0.7174502
E -0.16756315 -0.4537194 -0.4526429 -2.5305094  0.6259726
           a          b           c          d          e
A  1.4956787 -2.1806464 -2.39572986  0.3520614 -1.4237890
E -0.4526429 -0.4537194 -0.16756315 -2.5305094  0.6259726
C  0.8757019 -0.9390429  0.06609669 -1.4306694  2.3288836
B  0.1551510  0.7013947 -0.15808608  0.2141887  1.4214606
D  2.6012038  0.1896782  2.57257207 -0.3290858 -0.7174502
           d          b           c          e          a
A  0.3520614 -2.1806464 -2.39572986 -1.4237890  1.4956787
B  0.2141887  0.7013947 -0.15808608  1.4214606  0.1551510
C -1.4306694 -0.9390429  0.06609669  2.3288836  0.8757019
D -0.3290858  0.1896782  2.57257207 -0.7174502  2.6012038
E -2.5305094 -0.4537194 -0.16756315  0.6259726 -0.4526429

memisc documentation built on May 2, 2019, 5:45 p.m.

Related to reorder.array in memisc...