unmatrix: Convert a matrix into a vector, with appropriate names

Description Usage Arguments Value Author(s) See Also Examples

View source: R/unmatrix.R

Description

Convert a matrix into a vector, with element names constructed from the row and column names of the matrix.

Usage

1
unmatrix(x, byrow=FALSE)

Arguments

x

matrix

byrow

Logical. If FALSE, the elements within columns will be adjacent in the resulting vector, otherwise elements within rows will be adjacent.

Value

A vector with names constructed from the row and column names from the matrix. If the the row or column names are missing, ('r1', 'r2', ..,) or ('c1', 'c2', ..) will be used as appropriate.

Author(s)

Gregory R. Warnes greg@warnes.net

See Also

as.vector

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# simple, useless example
m <- matrix( letters[1:10], ncol=5)
m
unmatrix(m)

# unroll model output
x <- rnorm(100)
y <- rnorm(100, mean=3+5*x, sd=0.25)
m <- coef( summary(lm( y ~ x )) )
unmatrix(m)

Example output

sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to locate valid perl interpreter
gdata: 
gdata: read.xls() will be unable to read Excel XLS and XLSX files
gdata: unless the 'perl=' argument is used to specify the location of a
gdata: valid perl intrpreter.
gdata: 
gdata: (To avoid display of this message in the future, please ensure
gdata: perl is installed and available on the executable search path.)
sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLX' (Excel 97-2004) files.

gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLSX' (Excel 2007+) files.

gdata: Run the function 'installXLSXsupport()'
gdata: to automatically download and install the perl
gdata: libaries needed to support Excel XLS and XLSX formats.

Attaching package: 'gdata'

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

    nobs

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

    object.size

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

    startsWith

     [,1] [,2] [,3] [,4] [,5]
[1,] "a"  "c"  "e"  "g"  "i" 
[2,] "b"  "d"  "f"  "h"  "j" 
r1:c1 r2:c1 r1:c2 r2:c2 r1:c3 r2:c3 r1:c4 r2:c4 r1:c5 r2:c5 
  "a"   "b"   "c"   "d"   "e"   "f"   "g"   "h"   "i"   "j" 
  (Intercept):Estimate             x:Estimate (Intercept):Std. Error 
          3.034964e+00           4.986514e+00           2.322292e-02 
          x:Std. Error    (Intercept):t value              x:t value 
          2.311961e-02           1.306883e+02           2.156833e+02 
  (Intercept):Pr(>|t|)             x:Pr(>|t|) 
         9.195167e-112          5.211260e-133 

gdata documentation built on May 2, 2019, 5:49 p.m.