merge_with_precedence {cmapR} | R Documentation

## Merge two `data.frame`s, but where there are common fields those in `x` are retained and those in `y` are dropped.

### Description

Merge two `data.frame`s, but where there are common fields those in `x` are retained and those in `y` are dropped.

### Usage

    merge_with_precedence(x, y, by, allow.cartesian = TRUE, as_data_frame = TRUE)

### Arguments

`x` | the `data.frame` whose columns take precedence
`y` | another `data.frame`
`by` | a vector of column names to merge on
`allow.cartesian` | boolean indicating whether it's ok for repeated values in either table to merge with each other over and over again.
`as_data_frame` | boolean indicating whether to ensure the returned object is a `data.frame` instead of a `data.table`. This ensures compatibility with GCT object conventions, that is, the `rdesc` and `cdesc` slots must be strictly `data.frame` objects.

### Value

a `data.frame` or `data.table` object

### See Also

data.table::merge

### Examples

    (x <- data.table::data.table(foo=letters[1:10], bar=1:10))
    (y <- data.table::data.table(foo=letters[1:10], bar=11:20,
      baz=LETTERS[1:10]))
    # the 'bar' column from y will be dropped on merge
    cmapR:::merge_with_precedence(x, y, by="foo")

[Package cmapR version 1.0.0 Index]