Home > database >  heading for row and col for data structure matrix in R programming
heading for row and col for data structure matrix in R programming

Time:02-16

enter image description hereConsider you want to implement a 3x3 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.

CodePudding user response:

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.

  •  Tags:  
  • r
  • Related