Eric Bell wrote: > 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. > Hi Eric, Using your example data frame,
matrix(as.numeric(unlist(dv)),nrow=dim(dv)[1]) gives you the matrix you want, and levels(unlist(dv)) unique(as.numeric(unlist(dv))) gives you the correspondence between character codes and numbers. Jim ______________________________________________ R-help@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.