[R] from character to numeric over multiple columns

Federico Calboli f.calboli at imperial.ac.uk
Fri Jul 21 13:02:02 CEST 2006

Prof Brian Ripley wrote:
> Are the columns factors or character?  I'll try to write code that copes 
> with both:
> nm <- unique(c(as.character(col1), as.character(col2), as.character(col3)))
> DF[] <- lapply(DF, function(x) match(x, nm))


it worked.


Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place, London W2 1PG

Tel  +44 (0)20 7594 1602     Fax (+44) 020 7594 3193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com

More information about the R-help mailing list