Converts a numeric matrix M into a dataframe D
with three columns (x, factor 1, factor 2)
where rows of M are ranks of factor 1 levels and columns of M are
ranks of factor 2 levels, missing values are assumed to be 0 or NA.
The resulting dataframe D has no missing values.
Usage
matrix2raw(M,l1,l2)
Arguments
M
Numeric matrix, with missing values assumed to be NA or 0.
l1
Optional numeric vector of level names of column 2 (factor 1)
of returned data frame. If missing it is assigned row numbers of M.
l2
Optional numeric vector of level names of column 3 (factor 2)
of returned data frame. If missing it is assigned column numbers of M.
Value
D
Data frame with three columns: (y,f1,f1). y: observations, i.e.
non-zero entries, in matrix. f1: factor 1, i.e. row number of M or l1.
f2: factor 2, i.e. column number of M or l2. D is ordered first by
factor 2 and then factor 1. D has no missing values.
Author(s)
Joerg Schaber
Examples
data(DWD)
M <- raw2matrix(DWD) # conversion to matrix
D1 <- matrix2raw(M) # back conversion, but with different level names
D2 <- matrix2raw(M,c(1951:1998),c(1:9)) # with original level names