0

I have an integer column that has factor applied to it:

col <- factor(list("3", "4", "3", "3"), labels = c("a", "b"), levels = c(3, 4))

If I convert that column to integer, I get:

> as.integer(col)
[1] 1 2 1 1

While I want to get original list of 3 and 4.

How can I achieve this?

Bulat
  • 6,869
  • 1
  • 29
  • 52
  • 2
    We had almost exactly the same question here [earlier today](http://stackoverflow.com/q/36836789/4770166) – RHertel Apr 25 '16 at 17:53

1 Answers1

0

The original values, 3 and 4, are permanently lost in your current code. The easiest way to keep them around is to use them as your labels.

col <- factor(list("3", "4", "3", "3"), labels = c("3", "4"), levels = c(3, 4))

Another way would be to store the mapping prior to factor conversion.

lmo
  • 37,904
  • 9
  • 56
  • 69