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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,227 questions

56,129 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 289 views
1 answer 265 views
1 answer 272 views
272 views asked Jul 8, 2021 by avibootz
1 answer 268 views
1 answer 294 views
1 answer 298 views
298 views asked Jul 10, 2021 by avibootz
1 answer 268 views
268 views asked Jul 10, 2021 by avibootz
...