1

I have many "problems" but i will try to split them up as good as i can. First i will present my code:

# Laster pakker
library(RODBC)
library(plyr)
library(lattice)
library(colorRamps)
library(Perfor)
# Picking up data 
query <- "select convert(varchar(10),fk_dim_date,103) fk_dim_date,fk_dim_portfolio, dtd_portfolio_return_pct, dtd_benchmark_return_pct, *  from nbim_dm..v_fact_performance 
where fk_dim_date > '20130103' and fk_dim_portfolio in ('6906', '1812964')
"

# Formatting SQLen 
query <- strwrap(query,width=nchar(query),simplify=TRUE)

# quering 
ch <- odbcDriverConnect("driver={SQL Server};server=XXXX;Database=XXXX;", rows_at_time = 1024)
result <- sqlQuery(ch, query, as.is=c(TRUE, TRUE, TRUE))
close(ch)

# Do some cleanup
`enter code here`resultt$v_d <- as.Date(as.POSIXct(t$v_d))

#split
y <- split(qt,qt$fk_dim_portfolio)

#making names 
new_names <- c("one","two")
for (i in 1:length(y){assign(new_names[i],y[[i]])})

So far so good:

The table that my SQL is running on has approx 178 diff. port_ids, some of which are useless and others that are highly useful. However i want this code to pull all fk_dim_ports (pulling: '6906', '1812964 was just for example purposes). After pulling the data i want to seperate it into n (now 178 sets) and make them xts objects which i have run into some trouble using:

qt <- xts(t[,-1],order.by=t[,1])

But works perfectly well if i don`t split the data using:

 y <- split(qt,qt$fk_dim_portfolio)

Assuming this will work, my intention is to create charts.PerformanceSummary(mydata) for every table of my previous created data frames.

If you have any tips on how to split, make timeseries objects and loop the generation of the charts i would highly appreciate this.

I am aware that this post probably don`t comply to your rules/customs etc, but thanks for helping.

Lars

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
  • 2
    As a side note: Using `packages <- c('RODBC', 'plyr', 'lattice', 'colorRamps', 'Perfor')` and then `lapply(packages, require, character.only = TRUE)` will cut down on the amount of times you write `library` (or `require`) and load all those packages at once. Just cleaner, in my opinion – Rich Scriven Mar 30 '14 at 19:05
  • Thanks for the tip, Great one :) – user2262528 Mar 30 '14 at 19:29

0 Answers0