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

From: Dieter Menne <dieter.menne_at_menne-biomed.de>
Date: Fri, 25 Apr 2008 07:22:07 +0000 (UTC)

Eric Bell <eric <at> ericjbell.com> writes:

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

Column-wise factor conversion can be handy, but often it bites.

# Assume you have the data file
m1 m2
A B
B C
C D

#---------------
# make sure that no column-wise factor conversion is done dv <- read.csv( "a.txt", header=TRUE,sep=" ",stringsAsFactors=FALSE) # find unique levels in the whole data set faklevels = unique(unlist(dv))
dv[] = lapply(dv,function(x) factor(x,levels=faklevels)) # now we have common levels for all columns, we can convert to numerics dv[] = lapply(dv,as.numeric)

# or combine the two above
#dv[] = lapply(dv,function(x) as.numeric(factor(x,levels=faklevels)))

Dieter



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 - 07:33:09 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 - 08:30:33 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