R transform a factor ID variable into a numeric ID variable

前端 未结 1 804
耶瑟儿~
耶瑟儿~ 2021-01-12 05:34

I have a programming doubt in R and I have no idea how to solve it after spending hours looking at potential responses on the internet and on Stack Overflow.

I have

相关标签:
1条回答
  • 2021-01-12 06:06

    In case, the levels are in different order, we can convert the column to factor with levels specified as the unique elements in that column, and then coerce it to numeric/integer.

    df1$Numericcolumnname <- as.numeric(factor(df1$Columnname, 
                      levels=unique(df1$Columnname)))
    
    0 讨论(0)
提交回复
热议问题