How to convert a factor to integer\numeric without loss of information?
See the Warning section of ?factor: In particular, as.numeric applied to a factor is meaningless, and may happen by implicit coercion. To transform a factor f to approximately its original numeric values, as.numeric(levels(f))[f] is recommended and slightly more efficient than as.numeric(as.character(f)). The FAQ on R has similar advice. Why is as.numeric(levels(f))[f] more efficent than as.numeric(as.character(f))? … Read more