Re: [R] Using image function to plot character values

From: Jim Lemon <jim_at_bitwrit.com.au>
Date: Fri, 25 Apr 2008 19:32:00 +1000

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_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 Fri 25 Apr 2008 - 09:38:30 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