How to replace values in a data frame with another value

1.9k Views Asked by At

I have huge data set. The columns contain values like A,B,C,D,E,F,G,H and I need to replace them with 1,2,3,4...

[1] "C" "C" "C" "C" "C" "A" "H" "G" "G" "G" "G" "G" "G" "G" "C" "C" "C" "C" "C"
[20] "C" "B" "B" "B" "H" "H" "H" "H" "H" "H" "G" "C" "A" "A" "A" "A" "A" "A" "A"
[30]----

Another similar problem is values in one column are more than 1000 and I need to replace them by unique numbers.

1

There are 1 best solutions below

3
On

try replace

replace function examples

in your case e.g.

replace(df, "A", 1)