我正在尝试以某种方式将两个表与一些代码连接起来,其中在一个列中,键可能是原始键的子集。
Event
id date ProductId quantity
a xyz 1234567 30
a abc 5826811 20
b def 3619100 10
b ghi 9268420 50
ProductDimension
code name type
234-567 p1 c1
826-81 p2 c2
61-9100 p3 c3
Result should be:
eventAU
id date ProductId quantity name type
a xyz 1234567 30 p1 c1
a abc 5826811 20 p2 c2
b def 3619100 10 p3 c3
从这个问题中得到提示,我正在尝试使用以下方法进行模糊连接:
ProductDimension$regex <- gsub("-", "", ProductDimension$code)
eventTbl <- tbl_df(Events)
prodcutTbl <- tbl_df(ProductDimension)
eventsAU <- regex_left_join(eventTbl , prodcutTbl , by = c(ProductId = "regex"))
但我得到以下异常:
Error: All columns in a tibble must be 1d or 2d objects: * Column `col` is NULL