[Blotter-commits] r820 - pkg/FinancialInstrument/sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Oct 15 04:11:22 CEST 2011


Author: peter_carl
Date: 2011-10-15 04:11:21 +0200 (Sat, 15 Oct 2011)
New Revision: 820

Modified:
   pkg/FinancialInstrument/sandbox/download.DJUBSindex.R
Log:
- eliminated second read of spreadsheet


Modified: pkg/FinancialInstrument/sandbox/download.DJUBSindex.R
===================================================================
--- pkg/FinancialInstrument/sandbox/download.DJUBSindex.R	2011-10-15 00:58:21 UTC (rev 819)
+++ pkg/FinancialInstrument/sandbox/download.DJUBSindex.R	2011-10-15 02:11:21 UTC (rev 820)
@@ -42,11 +42,12 @@
   sheetnames=c("Excess Return", "Total Return")
   for(sheet in sheetnames){  
     print(paste("Reading", sheet, "sheet... This will take a moment..."))
-    x = read.xls("DJUBS_full_hist.xls", sheet=sheet, pattern="Symbol")
+    x = read.xls("DJUBS_full_hist.xls", sheet=sheet)
     
-    # Get the descriptions to add as attributes
-    # @ TODO: There must be a better way
-    x.attr = read.xls("DJUBS_full_hist.xls", sheet=sheet, pattern="Date", nrows=1, header=FALSE)
+    # Add column names, get the descriptions to add as attributes
+    colnames(x)=t(as.data.frame(apply(x[2,], FUN=as.character, MARGIN=1), stringsAsFactors=FALSE))
+    x.attr = t(as.data.frame(x[1,], stringsAsFactors=FALSE))
+    x=x[-1:-2,]
     
     # Get rid of the last line, which contains the disclaimer
     x=x[-dim(x)[1],]



More information about the Blotter-commits mailing list