I have a data frame put together from FRED data, I'm trying to find the proportion of times each variable has indicated a recession correctly. I've mutated the data to give me a T/F output if each variable is indicating a recession.
How do I tell R to look at, for example, if the bondyieldTF is indicating a recession(TRUE), then look at RecessionTF variable to see if (say in the next 4 observations) RecessionTF returns TRUE?
I have yet try try anything because I don't know where to begin (what to look up) to solve my problem.
bondyieldTF RecessionTF
<lgl> <lgl>
1 TRUE FALSE
2 TRUE FALSE
3 TRUE FALSE
4 TRUE TRUE
5 TRUE TRUE
6 FALSE TRUE
7 FALSE TRUE
8 FALSE TRUE
9 FALSE TRUE
10 FALSE TRUE
11 FALSE FALSE
So what I want is to look at bondyieldTF
, if in row 5, it is TRUE
then look at RecessionTF
Row 5,6,7,8, if any of those are TRUE
, bondyieldTF
was correct. If there are no true in RecessionTF
Row 5,6,7,8, then BondyieldTF
was incorrect.
EconFrame %>%
if (bondyieldTF == TRUE){
if (RecessionTF == TRUE){
Indication = Correct
} else {
Indication = Incorrect
}
}
This is the best I can come up with, and it says
Error in if (.) bondyieldTF == TRUE else { : the condition has length> 1