Consider a dataset with features X1,X2 and response variable Y which has 8 classes namely 1,2,3,4,5,6,7,8. How can I use R to convert these 8 class problem into four class problem s.t when
Y=1 or 2, class =I
Y=3 or 4, class =II
Y=5 or 6, class =III
Y=7 or 8, class =Iv
or similarly 32 class problem 8 class problem or 16 class problem. Is it something related to mapping function in R?
Currently what I am doing is, checking each class value if it is 1, I change it to I if it is 2 , I change it to I again?
Any simpler approach ? or advice would be appreciated.
You can get the ceiling
of Y/2
. If you like, you can convert to Roman numerals using as.roman
Y <- c(1, 2, 3, 4, 5, 6, 7, 8)
as.roman(ceiling(Y/2))
#> [1] I I II II III III IV IV