Reputation: 3
I have seen the code somewhere, but haven't found it in the 30 mins I've been searching.
Here's the code I have for now
library('quantmod')
today <- Sys.Date()
getSymbols("SBUX")
retSBUX <- dailyReturn(SBUX)
starbucks <- data.frame(SBUX)
starbucks[,7] <- as.Date(row.names(starbucks))
row.names(starbucks) <- NULL
starbucks <- subset(starbucks, starbucks[,7] >= "2015-04-06" && starbucks[,7] <= today)
When I run this code, I get a data frame with 0 variable and just the column names in the data frame.
Upvotes: 0
Views: 71
Reputation: 10612
You should used the vectorized logical operator &
instead of the short-circuit operator (&&
):
starbucks <- subset(starbucks, starbucks[,7] >= "2015-04-06" & starbucks[,7] <= today)
See R - boolean operators && and ||.
Upvotes: 1