I know the header sounds confusing but thats what I have now:
ticker<-c("AAPL","TSLA")
quantmod::getQuote(ticker)$'Trade Time'
[1] "2022-12-21 16:00:04 EST" "2022-12-21 16:00:04 EST"
The above line works normally, however, when I turn this line to a function like below:
trade_time<-function(ticker){
quantmod::getQuote(ticker)$'Trade Time'
trade_time
}
The output is as follows:
> trade_time(ticker)
function(ticker){
quantmod::getQuote(ticker)$'Trade Time'
trade_time
}
May I know what is the function missing in order to show the output? Many thanks.
trade_timeat the end. i.e. you just needquantmod::getQuote(ticker)$'Trade Time'R, the value of the last statement in the function in returned by default unless you have areturnbefore that line. i.e suppose you have a functionf1 <- function(x) {if(x > 10) {return("Yes"); "hello"}; return("Not TRUE")}The default case is returned if it is not TRUE i.e.f1(5) [1] "Not TRUE"and the other casef1(11)# [1] "Yes"Note that here we providedreturn, so the last statement with "hello" is not returned