Recoding variables with R

后端 未结 5 680
长情又很酷
长情又很酷 2020-11-28 04:36

Recoding variables in R, seems to be my biggest headache. What functions, packages, processes do you use to ensure the best result?

I\'ve found very few useful exam

5条回答
  •  死守一世寂寞
    2020-11-28 05:15

    I find this very convenient when several values should be transformed (its like doing recodes in Stata):

    # load package and gen some data
    require(car)
    x <- 1:10
    
    # do the recoding
    x
    ## [1]   1   2   3   4   5   6   7   8   9  10
    
    recode(x,"10=1; 9=2; 1:4=-99")
    ## [1] -99 -99 -99 -99   5   6   7   8   2   1
    

提交回复
热议问题