Recode numeric values in R

前端 未结 3 385
一向
一向 2021-01-12 18:09

I want to recode some numeric values into different numeric values and have had a go using the following code:

survey$KY27PHYc <- revalue(survey$KY27PHY1, c

3条回答
  •  孤街浪徒
    2021-01-12 18:58

    Try this:

    #sample data
    set.seed(123); x <- sample(1:5, size = 10, replace = TRUE)
    
    x
    # [1] 2 4 3 5 5 1 3 5 3 3
    
    #recode
    x <- c(1, 1, 2, 2, 3)[ x ]
    
    x
    # [1] 1 2 2 3 3 1 2 3 2 2
    

提交回复
热议问题