[R] numeric to factor via lookup table

Jonathan Greenberg jgrn at illinois.edu
Fri Mar 28 21:38:37 CET 2014


R-helpers:

Hopefully this is an easy one.  Given a lookup table:

mylevels <- data.frame(ID=1:10,code=letters[1:10])

And a set of values (note these do not completely cover the mylevels range):

values <- c(1,2,5,5,10)

How do I convert values to a factor object, using the mylevels to
define the correct levels (ID matches the values), and code is the
label?

--j

-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
259 Computing Applications Building, MC-150
605 East Springfield Avenue
Champaign, IL  61820-6371
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007



More information about the R-help mailing list