<html><body><div>Hello - I'm hoping someone has solved this already but I am trying to run the table.calendarreturns function in performanceanalytics for many funds and then export the data to a csv file (I'm interested in comparing monthly returns between funds).  The code itself runs fine, it's the presentation in the CSV file that's a problem.  I'd like to have the output for each fund show up vertically on top of each other in the csv file the exact same way the output shows up in the console after the code is run.    Right now the way the data is exported all the monthly returns for the funds show up in one long horizontal row for each year.  Evidently I need to add another line or two of code to manipulate the data for export</div><div><br data-mce-bogus="1"></div><div>Thanks for any help!</div><div><br data-mce-bogus="1"></div><div>Here's an example along w/ a sample data template</div><div>library(PerformanceAnalytics)</div><div>library(timeSeries)<br>library(fPortfolio)<br>library(quantmod)<br>library(caTools)</div><div><br data-mce-bogus="1"></div><div>returns <- read.csv("example.csv")</div><div>lct <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")<br>returns[,1] = as.Date(as.character(returns[,1]),format="%d-%b-%y") <br>Sys.setlocale("LC_TIME", lct)<br><br>returns.saved <- returns ## Saves the data if it needs to be reset later.</div><div>start.date <- returns[,1][1] ##Default start date; use this when you want entire data set</div><div>TickerListexcel <- colnames(returns[,-1])<br><br>#Creating time series object<br>returns = timeSeries(returns[,-1], charvec = returns[,1])<br>#colnames(returns) <- abbreviate(colnames(returns),minlength=6)<br>str(returns)<br>returns</div><div><br data-mce-bogus="1"></div><div>###CALENDAR RETURNS LOOP FOR MANY FUNDS<br># Calendar Tables<br>cal.list <- list()<br>for (i in 1:dim(returns)[2]) {<br> cal.list[[i]] <- table.CalendarReturns(returns[,i], digits=2, as.perc = TRUE)<br>}<br>names(cal.list) <- TickerListexcel<br>write.csv(cal.list,file="Calendar Year Returns.csv")</div><div><br data-mce-bogus="1"></div></body></html>