Description Usage Arguments Value Author(s) Examples
This is a wrapper for the merge
function from the base
package. merge
does not maintain variable attributes. mergeAttr
might
be useful if variable attributes should be maintained.
1 2 3 4 |
x |
first data frame to be merged. |
y |
second data frame to be merged. |
by |
specifications of the columns used for merging |
by.x |
specifications of the columns used for merging |
by.y |
specifications of the columns used for merging |
all |
logical; |
all.x |
logical; if |
all.y |
logical; analogous to |
sort |
logical. Should the result be sorted on the |
suffixes |
a character vector of length 2 specifying the suffixes to be used for making unique
the names of columns in the result which not used for merging (appearing in |
setAttr |
Logical: restore the variable attributes? If FALSE, the behavior of |
onlyVarValLabs |
Logical: If TRUE, only the variable and value labels will be restored. If FALSE, all variable attributes will be restored. |
homoClass |
Logical: Beginning with R version 3.5, |
data frame. See the help page of merge
for further details.
Sebastian Weirich
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ### data frame 1, variable 'y' with variable.label 'test participation'
df1 <- data.frame ( id = 1:3, sex = factor ( c("male", "male", "female")), y = c(TRUE,FALSE,FALSE))
attr(df1[,"y"], "variable.label") <- "test participation"
### data frame 2 without labels
df2 <- data.frame ( id = c(2,4), status = factor ( c("married", "single")), z = c(TRUE,FALSE))
### lost label after merging
df3 <- merge(df1, df2, all = TRUE)
attr(df3[,"y"], "variable.label")
### maintain label
df4 <- mergeAttr(df1, df2, all = TRUE, onlyVarValLabs = FALSE)
attr(df4[,"y"], "variable.label")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.