I am trying to create a simple ifelse
statement using tidyquant
or dplyr
.
What I currently have is;
from <- "2017-07-09"
to <- "2018-12-01"
getSymbols("GOOG", from = from, to = to, src = "yahoo", adjust = TRUE)
colnames(GOOG) <- c("Open", "High", "Low", "Close", "Volume", "Adjusted")
library(dplyr)
library(tidyquant)
GOOG %>%
mutate(Direction = ifelse(Close < Open, 1, 0))
Which returns an error:
Error in UseMethod("mutate_") :
no applicable method for 'mutate_' applied to an object of class "c('xts', 'zoo')"
I know the tidyquant
package can use dplyr
functions on xts
data so I am also trying to use the tidyquant
to get around this issue.
The following works but takes the data out of the xts
format.
x <- GOOG %>%
data.frame() %>%
mutate(Direction = ifelse(Close < Open, 1, 0))