I tried to produce a mutation of numeric data into "high","medium" and "low" via
library(dplyr)
mdata %>%
mutate(mvariable = case_when(vari < quantile(vari,0.5) ~ 'low',
between(vari, quantile(vari, 0.5), quantile(vari, 0.75))~'med',
TRUE ~ 'high'))
to use it in a multi level analysis.
It didn't generate my desired data but told me:
between() called on numeric vector with S3 class
what am I doing wrong?
Thanks in advance.
I am using R version 4.1.2 -- "Bird Hippie"
One alternative solution (without knowing the data) could be to circumvent the between
function entirely by switching the order of the case_when
:
library(tidyverse)
mdata <- mdata %>%
mutate(mvariable = case_when(vari < quantile(vari, 0.5) ~ 'low',
vari > quantile(vari, 0.75) ~ 'high',
TRUE ~ 'med'))