I have a data.frame df with date df$Date and a close df$Close column.
I am trying to get yearly returns but I am having problems
I tried
library(quantmod)
yr <- data.frame( periodReturn(df, period='yearly', subset='2008::'))
and also having date as rownames, but cannot get it to work.
Thank you for your help.
Your code almost works if you just convert to
xts. If you’re having difficulty converting yourdata.frametoxts, then provide more info about your data as requested in the comments of your question.