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%