coding variable values into classes using R

前端 未结 5 2020
灰色年华
灰色年华 2020-12-09 12:56

I have a set of data in which I need to code values of certain variables (numeric) into 3 classes.

My data set is similar to this but has 60 more variables:

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 13:22

    Just to show an alternate (similar to recode in SPSS) method from package car:

    > data$SWT <- with(data, recode(wt, "lo:200=1; 300:hi=3; else=2"))
    > data
       anim    wt SWT
    1     1 181.0   1
    2     2 179.0   1
    3     3 180.5   1
    4     4 201.0   2
    5     5 201.5   2
    6     6 245.0   2
    7     7 246.4   2
    8     8 189.3   1
    9     9 301.0   3
    10   10 354.0   3
    11   11 369.0   3
    12   12 205.0   2
    13   13 199.0   1
    14   14 394.0   3
    15   15 231.3   2
    

提交回复
热议问题