Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I obtain a dataframe from an array?

I’d like to transform my array into a dataframe, with the column "Cluster" where there will be the numbers 5,4,2,1, … and "Trend" with numbers 1,2,3,4,…

           [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] 
  cluster    5    4    2    1    2    4    1    2    2     5     1    

What I expect :

               Trend               Cluster
               1                   5
               2                   4
               3                   2
               4                   1
               ...

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

With data.frame:

data.frame(Trend = seq_along(mat), t(mat))

#   Trend cluster
# 1     1       5
# 2     2       4
# 3     3       2

Reproducible data:

mat <- t(c(5, 4, 2))
rownames(mat) <- "cluster"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading