calculate an equation based on conditional existing data I'm trying to figure out which method to go about calculating an equation based on variables from my database. I have the variables sex, which is 0 for males and 1 for females. I also have serum creatinine which I want in the case of females to be either $\leq 0.7$ or >0.7 and in men either $\leq 0.9$ or >0.9.
I've got an example of how it's done in another program and it looks something like this:
gen pre_creatinine=kreapreop/88.42
gen pre_egfr=0

replace pre_egfr=144*((pre_creatinine/0.7)^-0.329)*(0.993)^age if female==1 & pre_creatinine <=0.7

replace pre_egfr=144*((pre_creatinine/0.7)^-1.209)*(0.993)^age if female==1 & pre_creatinine >0.7

replace pre_egfr=141*((pre_creatinine/0.9)^-0.411)*(0.993)^age if female==0 & pre_creatinine <=0.9

replace pre_egfr=141*((pre_creatinine/0.9)^-1.209)*(0.993)^age if female==0 & pre_creatinine >0.9

I don't have access to this so I am working in R instead and I have gotten stuck here. I hope someone can help me.
The main question
Is there a command I can use that works like if_else or case_when but allows me to have the answer of an equation based on my data instead of a "label" in the new collum I'm making?
Or am I just all wrong? I'm sorry if I am unclear, this is new to me and I'm learning on my own.
I have tried the following, and get I get this in return:
"Error in eval_tidy(pair$lhs, env = default_env) : 
  object 'Sex_male_0_female_1' not found": 

library(dplyr) 

library(tidyverse) 

library(readxl) 

AKI <- read_excel("C:/Users/fredr/OneDrive/Skrivbord/Ny mapp/Excell försök/AKI.xlsx") 

AKI%>% select(Study_ID, Age, Sex_male_0_female_1, pat_height, pat_weight, eGFR_preop, eGFR_POD_1, eGFR_POD_2, Krea_preop, Krea_POD_1, Krea_POD_2, Krea_POD_3, Krea_POD_4, Krea_POD_5, Krea_POD_6, Krea_POD_7, PHLF ISGLS (A=1, B=2, C=3, na=4), Liver failure  (50:50) (yes 1, no 0, na 2), PHLF ISGLS clin rel (B+C) yes=1,  (No+A) no=0, na=2)%>% 

mutate(pat_height = pat_height/100) %>% 

mutate(BMI = pat_weight/pat_height^2)%>% 

mutate(pre_creatinine=Krea_preop/88.42)%>% eGFR_preop <- case_when(Sex_male_0_female_1 == 1 & pre_creatinine <=0.7 ~ 144*((pre_creatinine/0.7)^-0.329)(0.993)^Age, 

Sex_male_0_female_1 == 1 & pre_creatinine >0.7 ~ 144((pre_creatinine/0.7)^-1.209)(0.993)^Age, 

Sex_male_0_female_1 == 0 & pre_creatinine <=0.9 ~ 141((pre_creatinine/0.9)^-0.411)(0.993)^Age,

Sex_male_0_female_1 == 0 & pre_creatinine >0.9 ~ 141((pre_creatinine/0.9)^-1.209)*(0.993)^Age)%>% view()```


I'm not sure what is doing your R code (I'm not very familiar with the tidiverse philosophy), but I think you are after this
fun <- function(x) {
  pre_creatinine <- x[1]
  age <- x[2]
  female <- x[3]
  
  if(female== 1 & pre_creatinine <=0.7)
    144*((pre_creatinine/0.7)^-1.209)*(0.993)^age
  
  if(female==1 & pre_creatinine >0.7)
    144*((pre_creatinine/0.7)^-1.209)*(0.993)^age
  
  if(female==0 & pre_creatinine <=0.9)
    141*((pre_creatinine/0.9)^-0.411)*(0.993)^age
  
  if(female==0 & pre_creatinine >0.9)
    141*((pre_creatinine/0.9)^-1.209)*(0.993)^age
} 

X <- cbind(AKI$pre_creatinine,AKI$age, AKI$female)
pre_egfr <- apply(X, 1, fun)

