[R] To add text in a matrix

Larry Hotchkiss larryh at udel.edu
Fri Jan 15 16:05:26 CET 2010


One way to add the text is to use a list with named elements for the row and column names:

>   (M <- matrix(1:9, ncol=3, byrow=TRUE,
+       dimnames=list(" "=LETTERS[1:3],
+                     "THIS IS AN EXAMPLE\nOF a 3x3 MATRIX"=LETTERS[1:3])) )
   THIS IS AN EXAMPLE
OF a 3x3 MATRIX
    A B C
  A 1 2 3
  B 4 5 6
  C 7 8 9

Larry Hotchkiss


--------------------------------- Original Post -----------------------------
Message: 7
Date: Thu, 14 Jan 2010 11:04:27 +0100
From: <carferper at alum.us.es>
To: r-help at r-project.org
Subject: [R] To add text in a matrix
Message-ID: <f61eaf1f1d8d7.4b4efa3b at us.es>
Content-Type: text/plain; charset=us-ascii

Dear colleagues,

I would need to add text (some rows of information) in a matrix. For example, given this matrix


1 2 3
4 5 6
7 8 9

I would need to add this info:

THIS IS AN EXAMPLE
OF a 3x3 MATRIX
1 2 3
4 5 6
7 8 9


I have been looking for a function that works similar to "fopen" in matlab, but unfortunately I have not found It in R.

Thank you in advance for your help!

Carlos Fernandez



More information about the R-help mailing list