0

I wrote a function, that takes input parameters and return data frame with results. When we select "monthly" we should get indexes for this period, if we select "quarterly" the date should grouped by quarter, "year" the date should be grouped by year.

It returns no value, when I try to invoke it. What I am doing wrong?

getData<-function(startDate, endDate, index, dateFrequency){
hedge<-read.csv("data.csv", header = TRUE)
date <- as.Date(hedge$Date, format="%d.%m.%Y")
hedge <- cbind(date, hedge[,-1])

if (dateFrequency == "monthly"){
str <- paste0("Select ", index, " from hedge where date        >=","'",startDate,"'"," and ","date <= ","'",endDate, "'")
d <- sqldf(str)
}
result <- d
return(result)
}

Revoking:

getData("31.01.1990","31.03.1990",1,"monthly")

Here is "data.csv" file:

Date    HFRIEHI HFRIEMNI    HFRIEHFG Index  HFRIEHFV Index  HFRIENHI Index  HFRISHSE Index
31.12.1989                      
31.01.1990  -3.3400%    1.2300%         -5.0700%    9.1500%
28.02.1990  2.8500% 1.2300%         1.6600% 2.1600%
31.03.1990  5.6700% 0.8200%         4.500%  0.9100%
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Beibut
  • 11
  • 2
  • Make sure you can actually connect to your sql database and then check that the startDate and endDate values you pass can be correctly read by the sql script and also that "select 1 from ..." makes sense.... – AntoniosK Aug 23 '15 at 18:48
  • 2
    `data.csv` is not a csv file so it is not going to work right from the start. The SQL statement is `select 1 from ...` which is not likely what you want. Maybe other errors too. – G. Grothendieck Aug 24 '15 at 00:05
  • data.csv is csv-file, I created it using Save-As. – Beibut Aug 24 '15 at 11:10
  • What you posted is not a csv file. – G. Grothendieck Aug 24 '15 at 18:43

0 Answers0