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

heading for row and col for data structure matrix in R programming

enter image description hereConsider you want to implement a 3×3 matrix in R, and wish to have row names and col names. What would be the appropriate code for it ?

I tried using row bind and col bind functionality but unable to figure out how to add a unique heading for each row and col.

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 :

Something like this?

matrix(1:9, 3, 3, dimnames=list(letters[1:3], LETTERS[1:3]))
#   A B C
# a 1 4 7
# b 2 5 8
# c 3 6 9

Note the first character vector provides the row names and the second provides the column names.

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