Hi,
I'm not necessarily anticipating a code fix, I supect it's more likely my approach is wrong. I am wondering if I should perhaps use some kind or loop, or other function, instead of ifelse?
I have a data set of daily foreign exchange prices, and I want to compare the high and low values of previous days/rows to identify the type of day that occured. I have tried using multiple comparisons in an if else argument with the '|' or operator. I get this error "... ! operations are possible only for numeric, logical or complex types". Note, I am using dplyr.
DT
Open High Low Close
1 135.146 135.146 135.146 135.146
2 135.184 137.128 135.180 136.430
3 136.430 136.644 135.539 135.713
4 135.713 136.866 135.680 136.809
5 136.809 136.935 135.514 136.273
6 136.273 136.893 136.253 136.591
My code attempt:
day_type <- DT %>%
mutate(d_type = ifelse(High < lag(High) & Low < lag(Low), "Up", "0") | #Up day
Low > lag(Low) & High > lag(High), "Down", "0" | #Down Day
High > lag(High) & Low > lag(Low), "Inside", "0" | #Inside Day
High < lag(High) & Low > lag(Low), "Outside", "0") #Outside Day
Advise much appreciated