I am trying to convert a set of variables as factored variable :
example in variable quality the values are : 3,4,5,6,7,8,9
I want a new FACTORED variable qual_level which has values low , medium and high such that
low <- quality(3,4)
medium<- quality(5,6,7)
high<- quality(8,9)
Hence I tried implementing following code .
q_levels <- a <- factor (white_wine$quality ,
c(3,4,5.6,7,8,9,10),
levels=1:3,
labels=c("Low", "Medium", "High"))
Above code throws an error :
Error in factor(white_wine$quality, c(3, 4, 5.6, 7, 8, 9, 10), levels = 1:3, : invalid 'labels'; length 3 should be 1 or 2
How can I improve the code ?