[R] Using image function to plot character values

From: Eric Bell <eric_at_ericjbell.com>
Date: Thu, 24 Apr 2008 14:37:09 -0700


Hello. I am a newbie to R. If I should be reading some FAQ or manual that could help answer my question please tell me and I will go there.

Problem:

I have a spreadsheet that contains a character code in each cell. The columns in the spreadsheet represent time and the rows represent people. I want to use the image function to display this information, but the image function requires numeric data. I know how to read in the spreadsheet into a data frame, but if I use data.matrix to convert data frame into a numeric matrix, each column gets converted separately, so that the same character code may get converted to a different numeric code depending on the column. How do I apply the character to numeric conversion so that each character gets converted to the same numeric value?

A secondary problem is that after I do the conversion, I need to know what codes were converted to what numeric values.

Example:

In the example below, "B" gets converted to 2 in the first column, but gets converted to 1 in the second column.

> dv <- read.csv( SourceFileName, header=TRUE)
> dv

  m1 m2
1 A B
2 B C
3 C D
> data.matrix(dv)

     m1 m2

[1,]  1  1
[2,]  2  2
[3,]  3  3

Thanks in advance,

--eric



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 24 Apr 2008 - 21:48:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 Apr 2008 - 10:30:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive