I need to change a column from numeric to factor based on the numeric value being higher or lower than 10.
For example with the following data:
age &
We could use cut
to change the numeric
to factor
column based on the condition
d.frame$hight <- cut(d.frame$hight, breaks = c(-Inf, 10, Inf),
labels = c('low', 'high'), right = FALSE)
As there are only two levels, another option would be to create a logical vector and use ifelse
to change the values
d.frame$hight <- factor(ifelse(d.frame$hight>=10, "high", "low"))