Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

combining 2 functions into one in R

ticker<-c("AAPL","TSLA")

quote<-function(ticker){
  quote<-quantmod::getQuote(ticker)$Last
  quote
}

trade_time<-function(ticker){
  quantmod::getQuote(ticker)$'Trade Time'
}

> quote(ticker)
[1] 131.57 128.91
> trade_time(ticker)
[1] "2022-12-22 11:33:56 EST" "2022-12-22 11:33:57 EST"

May I know if there is a way I can combine the 2 functions into one? Thanks a lot.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

We could extract both the columns at once by selecting the columns from the data

trade_time <- function(ticker)
{

quantmod::getQuote(ticker)[, c("Trade Time", "Last")]
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading