"text": "Combine Tables\n\nx <- tribble(\n ~A, ~B, ~C,\n \"a\", \"t\", 1,\n \"b\", \"u\", 2,\n \"c\", \"v\", 3\n)\n\ny <- tribble(\n ~A, ~B, ~D,\n \"a\", \"t\", 3,\n \"b\", \"u\", 2,\n \"d\", \"w\", 1\n)\n\n\nCombine Variables\n\nbind_cols(..., .name_repair): Returns tables placed side by side as a single table. Column lengths must be equal. Columns will NOT be matched by id (to do that look at Relational Data below), so be sure to check that both tables are ordered the way you want before binding.\n\n\n\nCombine Cases\n\nbind_rows(..., .id = NULL): Returns tables one on top of the other as a single table. Set .id to a column name to add a column of the original table names.\n\n\n\nRelational Data\nUse a “Mutating Join” to join one table to columns from another, matching values with the rows that the correspond to. Each join retains a different combination of values from the tables.\n\nleft_join(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ..., keep = FALSE, na_matches = \"na\"): Join matching values from y to x.\nright_join(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ..., keep = FALSE, na_matches = \"na\"): Join matching values from x to y.\ninner_join(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ..., keep = FALSE, na_matches = \"na\"): Join data. retain only rows with matches.\nfull_join(x, y, by = NULL, copy = FALSE, suffix = c(\".x\", \".y\"), ..., keep = FALSE, na_matches = \"na\"): Join data. Retain all values, all rows.\n\nUse a “Filtering Join” to filter one table against the rows of another.\n\nsemi_join(x, y, by = NULL, copy = FALSE, ..., na_matches = \"na\"): Return rows of x that have a match in y. Use to see what will be included in a join.\nanti_join(x, y, by = NULL, copy = FALSE, ..., na_matches = \"na\"): Return rows of x that do not have a match in y. Use to see what will not be included in a join.\n\nUse a “Nest Join” to inner join one table to another into a nested data frame.\n\nnest_join(x, y, by = NULL, copy = FALSE, keep = FALSE, name = NULL, ...): Join data, nesting matches from y in a single new data frame column.\n\n\n\nColumn Matching for Joins\n\nUse by = join_by(col1, col2, …) to specify one or more common columns to match on.\n\nleft_join(x, y, by = join_by(A))\nleft_join(x, y, by = join_by(A, B))\n\nUse a logical statement, by = join_by(col1 == col2), to match on columns that have different names in each table.\n\nleft_join(x, y, by = join_by(C == D))\n\nUse suffix to specify the suffix to give to unmatched columns that have the same name in both tables.\n\nleft_join(x, y, by = join_by(C == D), suffix = c(\"1\", \"2\"))\n\n\n\n\nSet Operations\n\nintersect(x, y, ...): Rows that appear in both x and y.\nsetdiff(x, y, ...): Rows that appear in x but not y.\nunion(x, y, ...): Rows that appear in x or y, duplicates removed. union_all() retains duplicates.\nUse setequal() to test whether two data sets contain the exact same rows (in any order).\n\n\nCC BY SA Posit Software, PBC •
[email protected] • posit.co\nLearn more at dplyr.tidyverse.org.\nUpdated: 2024-05.\n\npackageVersion(\"dplyr\")\n\n[1] '1.1.4'"
0 commit comments