I´m trying to insert a column in a dataframe named Reference with returns of stocks obtained from another dataframe called Quotes.
Quotes <- data.frame (Ticker = c("Petr4","Petr4","Petr4","Abev3","Abev3","Petr4","Petr4","Abev3","Abev3","Abev3" ),
Close = c(15.80,15.55,15.90,18.52,19.57,16.25,16.50,19.20,19.18,19.7))
Reference <- aggregate(cbind(Close) ~ Ticker, data = (Quotes), FUN = last)
This is how the inserted column would like (Last N Days return):
Reference$Return <- c(0.044303797,0.063714903)
I´m using Quantmod FUN Last to get the last quote, any other idea?