cartesian product with dplyr R

前端 未结 6 562
清酒与你
清酒与你 2020-12-03 07:06

I\'m trying to find the dplyr function for cartesian product. I\'ve two simple data.frame with no common variable:

x <- data.frame(x=c(\"a\",\"b\",\"c\"))         


        
6条回答
  •  隐瞒了意图╮
    2020-12-03 07:20

    Apologies to all: the below example does not appear to work with data.frames or data.tables.

    When x and y are database tbls (tbl_dbi / tbl_sql) you can now also do:

    full_join(x, y, by = character())

    Added to dplyr at the end of 2017, and also gets translated to a CROSS JOIN in the DB world. Saves the nastiness of having to introduce the fake variables.

提交回复
热议问题