Recode/relevel data.frame factors with different levels

后端 未结 4 1156
予麋鹿
予麋鹿 2020-12-25 08:44

Each time when I have to recode some set of variables, I have SPSS recode function in mind. I must admit that it\'s quite straightforward. There\'s a similar recode

4条回答
  •  再見小時候
    2020-12-25 09:04

    Yes, just assign to levels:

    R> set.seed(100)
    R> x <- as.factor(round(runif(100,1,7)))
    R> table(x)
    x
     1  2  3  4  5  6  7 
     3 16 20 19 18 17  7 
    R> levels(x) <- LETTERS[1:7]
    R> table(x)
    x
     A  B  C  D  E  F  G 
     3 16 20 19 18 17  7 
    R> 
    

提交回复
热议问题