I searched "cut mutate add label" and did not find a similar post.
I have various columns of lab values and am converting each one up to a score, they all get added up and the total is used to access a patients mortality. One of them, below (reprex with fake data), isn't working and the rest are.
I'm curious as to why a label is present that I did not choose (I have either a 4, 3, 2, 1 or 0) and why it is backwards (5 should be labeled a 4, not a 1).
library(tidyverse)
df<-
tibble::tribble(
~plt,
5,
25,
75,
125,
250,
)
df %>%
mutate(sofa_plt = as.numeric(cut(plt, breaks=c(0,19,49,99,149,1000), include.lowest=TRUE, labels=c("4", "3", "2", "1", "0"), ordered_result = TRUE)))
#> # A tibble: 5 x 2
#> plt sofa_plt
#> <dbl> <dbl>
#> 1 5 1
#> 2 25 2
#> 3 75 3
#> 4 125 4
#> 5 250 5