I'm writing a function in R with two dataframes in it, but I need some help. I have two tables, one with the cutoff values for hypotension in children and one big database of my patients. They look like this:
hypotension<-data.frame(age=c(1:18), boys=c(66,76,78,82,84....), girls=c(66,75,78,83, 85...)
database<-data.frame(patient_nr=c(1:1000), age=c(M,F,M,M,F...), gender, bloodpressure, heartrate, operation)
I want to know if the patients in my database have hypotension and tried to make a function for it, but couldn't make one that worked yet.
So far, my function looks like this:
got_hypotension <- function(hypotension, database){
X<-ifelse(database$gender=="M" & database$age==hypotension$age, print(hypotension$boys),
ifelse(database$gender=="F" & database$age==hypotension$age, print(hypotension$girls),
ifelse(database$age>18, print(90), 999)))
if(database$bloodpressure<X & !is.na(database$bloodpressure) {
print("YES")}}
I understand that this doesnt work, I need to find a way that R, for each patient, looks at age in the database, find the same age in my hypotension table and use that specific cutoff value for the patients bloodpressure, but I have no clue how to do this. Can anybody help me, any help would be appreciated!