Convert a matrix to a cfda data.frame

matrixToCfd(X, times = NULL, labels = NULL, byrow = FALSE)

Arguments

X

matrix containing the states

times

time values. If NULL, it uses a sequence of integers starting with 1

labels

id labels. If NULL, it uses the matrix colnames

byrow

if FALSE, one column = one trajectory

Value

a data.frame in the cfda format

See also

Examples

x <- matrix(c("a", "b", "c", "c",
              "c", "a", "a", "a",
              "b", "c", "a", "b"), ncol = 4, byrow = TRUE,
              dimnames = list(NULL, paste0("ind", 1:4)))
matrixToCfd(x)
#>      id time state
#> 1  ind1    1     a
#> 2  ind1    2     c
#> 3  ind1    3     b
#> 4  ind2    1     b
#> 5  ind2    2     a
#> 6  ind2    3     c
#> 7  ind3    1     c
#> 8  ind3    2     a
#> 9  ind3    3     a
#> 10 ind4    1     c
#> 11 ind4    2     a
#> 12 ind4    3     b