r - How to rename group values into ordered values without reordering total data frame? -


in large datafile need rename grouping variables ordered number. there easy way that?

this example of want do:

  group value 1     3     1 2     3     2 3     3     3 4     1     4 5     1     5 6     1     6 7     2     7 8     2     8 9     2     9 

this data frame want change (by renaming group variable):

  group value 1     1     1 2     1     2 3     1     3 4     2     4 5     2     5 6     2     6 7     3     7 8     3     8 9     3     9 

so, want rename group value ordered numbers, without reordering total data frame. has have idea how this? many in advance!

you can try factor

df1$group <- as.numeric(factor(df1$group, levels=unique(df1$group))) 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -