函数返回R中的句点值

时间:2015-08-23 18:23:07

标签: r csv financial

我编写了一个函数,它接受输入参数并返回带有结果的数据框。当我们选择"monthly"时,我们应该获得此期间的索引,如果我们选择"quarterly"日期应按季度分组,"year"日期应按年分组。

当我尝试调用它时,它不返回任何值。我做错了什么?

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)
}

撤消:

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

这是"data.csv"档案:

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%

0 个答案:

没有答案