[R] Row names and matrixs

nielsen4897 lindseynielsenpc at gmail.com
Thu May 12 04:23:33 CEST 2011


Hi all - 
I am NEW to R and NEW to any type of programming.  I am making heatmaps
using the heatmap.2 function within gplots package.  At present, when the
heatmap is plotted it uses the row identifiers as 1,2,3,4...etc.  However, I
much rather use my own labels.  I was told my another well-versed R
programmer to use the follow script:
x<-as.matrix(test1[,-1])  ## skip column 1
rownames(x)<- test[1,]
heatmap(x, scale="none")  

This was for data set up in 4 columns such as when you read the data in R it
looks like:
        Loci      Cont     NaCl     Peg
1      0231     2.1       4.2       4.1
2      1253     4.1       2.3      2.3
3      8167     5.7       1.1      3.4

Using the script above and this dataset it worked well - the Loci was used
as the row labels rather than the numbers assigned by R.  
Looking at the data after this script it looks like:
             Loci      Cont     NaCl     Peg
0231     0231     2.1       4.2       4.1
1253      1253     4.1       2.3      2.3
8167      8167     5.7       1.1      3.4


Now, I want to do the same thing BUT my dataset looks like this:
       Loci       NaCl     Peg
1      0231     23.2       34.1
2      1253     25.3      21.3
3      8167     21.1      38.4

When I put in the script
x<-as.matrix(test1[,-1])  ## skip column 1
rownames(x)<- test[1,]
heatmap(x, scale="none")  
 
This is what follows (after looking at the dataset change)
          NaCl       Peg
[1,]    23.2       34.1
[2,]    25.3       21.3
[3,]    21.1       38.4

If I alter the -1 in the x<-as.matrix(test1[,-1])  line it will 'skip' other
columns but not the first one.

What do I need to enter to make the dataset look like ?
              Loci       NaCl     Peg
0231      0231     23.2       34.1
1253      1253     25.3      21.3
8167      8167     21.1      38.4

Please explain the answer and WHAT the #'s inside the [] mean!

Thanks



--
View this message in context: http://r.789695.n4.nabble.com/Row-names-and-matrixs-tp3516372p3516372.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list