#' Create main df structure
#'
#' Create main df with important columns that sub-identify the ID (code.) such as stock., latest price, latest daily return
#'
#' Return: df
#' @importFrom magrittr %>%
#' @param plot_df
#' @keywords main df
#' @export
main_df_f <- function(df = plot_df){
lastvalue_f <- function(v){return(v[length(v)])}
return_f <- function(v){
L <- length(v)
if(L>1){
return(v[L]/v[L-1] - 1)
}else{
return(NA)
}
}
mdf1 <- df %>% group_by(code) %>% summarise(stock = lastvalue_f(stock), date = lastvalue_f(date), chg = return_f(close),
close = lastvalue_f(close))
return(mdf1)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.