I need to date and time of the data that satisfies a condition in ifelse.
Glucose_4h <- character()
for(i in 1:96){
A <- unlist(difftime(Time_Meal[i], Time_Glucose[1:15372], units="mins"))
B <- ifelse(as.numeric(A)>0 & as.numeric(A)<5.0, "Inc_G","Exc_G")
Glucose_4h <- c(Glucose_4h,B)
}
In this code I also need which Time_Glucose satisfied the condition Could you help me about this?
So you need the values of
Time_GlucosewhereGlucose_4his equal to"Inc_G"? In your exampleBwill always be 15372 long (the length ofTime_Glucose. You could then capture that along with what you're currently doing:Then, if you only want the ones where
Glucose_4h == "Inc_G", you could do the following: