You can use the merge
function in R to bind matching rows of two dataframes and keep the unmatching columns. You can specify the columns to merge by using the by
argument. Here is an example:
301 chars10 lines
In this example, the by
argument specifies the column on which to merge (ID
in this case). The all = TRUE
argument keeps all rows from both dataframes, merging only the rows with matching ID
, while keeping the unmatching columns (Name
in df1
and Age
in df2
) in the resulting dataframe.
gistlibby LogSnag