Skip to content
Back to formatted view

Raw Message

Message-ID: <47ECB7DC.1030707@bitwrit.com.au>
Date: 2008-03-28T09:18:20Z
From: Jim Lemon
Subject: Converting a data frame to matrix
In-Reply-To: <c96452060803271743h11869c29t695a037567d1ed7a@mail.gmail.com>

Adrian Johnson wrote:
> Hello:
> 
> I have a tab delim file with 100 rows and 100 columns.
> 
> I have numerical values in this table. What I want is to create an image
> color map with color gradation.
> 
> my values range from -5 to 0. max value is 0.
> 
> to acheive this, I need to convert my data.frame into matrix.
> 
> I tried following :
> 
> mydf <- read.table('mytable',sep='\t',header=T)
> mydf1 <- mydf[,2:100]
> colnames(mydf1) <- as.character(mydf[,1])
> 
> here comes the trouble:
> 
> mymat <- as.matrix(mydf1)
> 
> -- numerical values become character values.  -1 becomes "-1"
> 
> mymat <- data.matrix(mydf1)
> 
> -- whole matrix is filled with 1,2 and 3.
> 
> Is there any other way I can do this.
> 
> say row names are city schools
> colnames  are student names
> 
Hi Adrian,
Have you looked at color2d.matplot in the plotrix package?

Jim