Skip to contents

Transforms a matrix to a long data.frame.

Usage

to_long(from, ...)

# S4 method for matrix
to_long(from, factor = FALSE, reverse = FALSE)

Arguments

from

An object to be coerced.

...

Currently not used.

factor

A logical scalar: should character string be coerced to factor? Default to FALSE, if TRUE the original ordering is preserved.

reverse

A logical scalar: should the order of factor levels be reversed? Only used if factor is TRUE. Useful for plotting.

Value

A coerced object.

See also

Other transformation tools: append(), assign()

Author

N. Frerebeau

Examples

## Create a matrix
A <- matrix(data = sample(0:10, 100, TRUE), nrow = 20, ncol = 5)

## Transform to long data.frame
head(to_long(A))
#>   row column value
#> 1   1      1     4
#> 2   2      1     8
#> 3   3      1    10
#> 4   4      1     8
#> 5   5      1     3
#> 6   6      1     3