1

I have the basic fund data,I want to add the manager name by the date range and the fund ID

I tried the fuzzy right join x = fuzzy_right_join(manager, fundret, by = c("fundName" = "fundName", "date"= "managerStartdate", "date" = "managerENDdate"), match_fun = list('==', '>', '<')) but have a error

Error in mf(rep(u_x, n_y), rep(u_y, each = n_x), ...) :could not find function "mf

and I tried some If /else functions to do,still doesnt't work......

library(lubridate)
manager=data.frame(managerName=c("A","B","C","D","E","F","G","H","I","J","K","L","M","N"),
                   fundName=c("fundA","fundA","fundA","fundA","fundA","fundA","fundA","fundA","fundA","fundA","fundA","fundB","fundB","fundC"),
                   managerStartdate=ymd(c("20040227","20041218","20140317","20140317","20120405","20151119","20140620","20150901","20100118","20150107","20051029","20140321","20130320","20140321")),
                   mangerENDdate=ymd(c("20051029","20050412","20151119","20170113","20130628","20170224","20150107","20170328","20140620","NA","20100118","20180912","20140430","20180912")))


fundret=data.frame(
                   fundName=c("fundA","fundA","fundA","fundA","fundA","fundA","fundB","fundC"),
                   date=ymd(c("20020628","20041003","20120508","20140321","20160101","20170201","20140707","20170909")),
                   ret=c(0.05,0.3,0.44444,0.00023,-0.0058,0.00006,-0.5,0.7))

And this is I wanted to joint

wantedresult=data.frame(
  fundName=c("fundA","fundA","fundA","fundA","fundA","fundA","fundB","fundC"),
  date=ymd(c("20020628","20041003","20120508","20140321","20160101","20170201","20140707","20170909")),
  ret=c(0.05,0.3,0.44444,0.00023,-0.0058,0.00006,-0.5,0.7),
  managerName=c("NA","A","I&E","C&D","D&J","J","L","N"))

Thanks for your help

manager:https://i.stack.imgur.com/sbfk7.jpg

fundret:https://i.stack.imgur.com/aQyj1.jpg

wantedresult:https://i.stack.imgur.com/DbWap.jpg

1 Answers1

0

If you use backticks instead of quotes in the match_fun arguments, it should work.

match_fun = list(backtick==backtick, backtick>backtick, backtick

backtick = `

Arthur Yip
  • 5,810
  • 2
  • 31
  • 50