I have the following test data:
df <- data.frame(group = c('Control' , 'Low' , 'Middle' , 'High') ,
type = c('A' , 'A' , 'A' , 'A') ,
value = c('3' , '5' , '2' , '4'))
I'm attempting to find each ratio for the values of "Low" , "Middle" , "High" against the value for "Control" - Low/Control, Middle/Control , High/Control.
I've trying this using mutate and ifelse, however, the function returns an NA.
df %>%
group_by(group) |>
mutate(value = ifelse(group == 'Low' , value / value[Trt == 'Control'] , value))
I'd like to find a function that will return the appropriate result for each of the ratios.