Skip to content
Prev 65230 / 398506 Next

How to convert a factor to a numeric?

# If fact1 and fact2 are your factors, let prm be the permutation such that
# levels(fact2) corresponds to ("aligns to") levels(fact1)[prm] . In your
example, the permutation is
# apparently the identity, (1:3).

#Then

levels(fact2)[prm[fact1]]==fact2

## does what you want. I wouldn't be surprised if there are cleverer
solutions, though.


-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box