[R] Using image function to plot character values
Eric Bell
eric at ericjbell.com
Thu Apr 24 23:37:09 CEST 2008
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
More information about the R-help
mailing list