(require '[incanter.core :as icore])
;; Assume dataset "data" is already loaded by incanter.core/read-dataset
;; Let's examine the columns (note that Volume is the 5th column)
(icore/col-names data)
==> [:Date :Open :High :Low :Close :Volume]
;; We CAN use the :Volume keyword to look at just that column
(icore/sel data :cols Volume)
==> (11886469 9367474 12847099 9938230 11446219 12298336 15985045...)
;; But we CANNOT use the :Volume keyword with filters
;; (well, not without looking up the position in col-names first...)
(icore/sel data :filter #(> (#{:Volume} %) 1000000))
显然这是因为过滤器的匿名函数正在查看 LazySeq,它不再将列名作为其结构的一部分,因此上面的代码甚至无法编译。我的问题是:Incanter 是否有办法执行此过滤查询,仍然允许我使用列关键字?例如,我可以让它工作,因为我知道 :Volume 是第 5 列
(icore/sel data :filter #(> (nth % 5) 1000000))
不过,我还是想看看 Incanter 是否有办法为这种类型的过滤查询保留 column 关键字。