Here is an example:
height
1 1.5
2 1.3
3 1.9
4 1.5
5 1.6
There are 1000 of them with height ranging from 0 to 1.9. And I want to cut them into 3 levels: low, medium and high. Then they are ordinal data.
result should look like this:
height
1 medium
2 low
3 high
4 medium
5 medium
And the summary should look like:
height
low: 203
medium: 723
high: 74
I tried to use the loop but then “low, medium and high” are characters, not levels.
Here is how I did the low part:
height_cuts = c(1.5,1.9)
for(i in 1:nrow(health.sample)){
if(is.na(health.sample$height[i])==FALSE){
if(health.sample$height[i] < height_cuts[1]){
health.sample$height[i] = low_h
}
}
}
1 Answer