I have a dataset in which I need to encode the values โโof certain variables (numeric) into 3 classes.
My dataset is similar to this, but has 60 more variables:
anim <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) wt <- c(181,179,180.5,201,201.5,245,246.4,189.3,301,354,369,205,199,394,231.3) data <- data.frame(anim,wt) > data anim wt 1 1 181.0 2 2 179.0 3 3 180.5 4 4 201.0 5 5 201.5 6 6 245.0 7 7 246.4 8 8 189.3 9 9 301.0 10 10 354.0 11 11 369.0 12 12 205.0 13 13 199.0 14 14 394.0 15 15 231.3
I need to encode the values โโof the variable "wt" to 3 classes: (wt> = 179 and wt <200) = 1; (wt> = 200 and wt <300) = 2; (wt> 300) = 3
who should give me this
> data2 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