matrix or data.frame to tibble (taken from tidyquant)

matrix_to_tibble(x, preserve_row_names = "row.names", ...)

Arguments

x

a matrix

preserve_row_names

give name to rownames column, if NULL discard rownames

...

further parameters passed to as_tibble

Examples

x <- matrix(rnorm(20), ncol=4)
rownames(x) <- LETTERS[seq_len(nrow(x))]
matrix_to_tibble(x)
#> # A tibble: 5 × 5
#>   row.names       V1      V2      V3     V4
#>   <chr>        <dbl>   <dbl>   <dbl>  <dbl>
#> 1 A         -2.52    -1.61    0.545  -1.26 
#> 2 B         -1.49    -0.0719  1.06    0.707
#> 3 C         -1.38    -1.55    0.0597  0.508
#> 4 D         -0.511    0.0988 -0.359   1.62 
#> 5 E          0.00332  1.03   -0.764  -0.252
!(is.matrix(x) || is.data.frame(x))
#> [1] FALSE