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

From: Dieter Menne <>
Date: Fri, 25 Apr 2008 07:22:07 +0000 (UTC)

Eric Bell <eric <at>> 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

# 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 mailing list PLEASE do read the posting guide 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 Please read the posting guide before posting to the list.

list of date sections of archive