R - Pitfalls in converting a factor to a numeric value

Sometimes when you’ve done some data manipulation or read a new file, it might happen that a numerical attribute, like an ID, is stored as a factor. Let’s have a look at the following example: Here I simply defined a vector of numbers (e.g. ids) and converted the values to factors.

1
2
3
id <- factor(seq(10000, 20000, 1))
> str(id)
 Factor w/ 10001 levels "10000","10001",..: 1 2 3 4 5 6 7 8 9 10 ...

Read More