Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,104 questions

40,777 answers

573 users

How to convert matrix to data frame with row names in R

1 Answer

0 votes
m = matrix(c(4, 7, 1, 3, 98, 12, 87, 31, 770, 500, 200, 100, 1111, 2222, 3333), ncol = 3)
  
print(m)
  
df = as.data.frame(t(m), row.names= c('nameA', 'nameB', 'nameC'))

print(df)
  
  
  
        
        
# run:
#
#      [,1] [,2] [,3]
# [1,]    4   12  200
# [2,]    7   87  100
# [3,]    1   31 1111
# [4,]    3  770 2222
# [5,]   98  500 3333
#        V1  V2   V3   V4   V5
# nameA   4   7    1    3   98
# nameB  12  87   31  770  500
# nameC 200 100 1111 2222 3333
#

 





answered Jul 10, 2021 by avibootz

Related questions

1 answer 137 views
1 answer 87 views
1 answer 88 views
88 views asked Jul 10, 2021 by avibootz
1 answer 84 views
84 views asked Jul 10, 2021 by avibootz
1 answer 82 views
82 views asked Jul 8, 2021 by avibootz
...