adat <- data.frame(id = c(1, 2, 3),
x1 = c(7, 3, 8))
bdat <- data.frame(id = c(1, 2),
x2 = c(5, 1))
cdat <- data.frame(id = c(2, 3),
y3 = c(7, 9))
ddat <- data.frame(id = 4,
y4 = 6)
# Merge adat, bdat, cdat, and data by the variable id
df.merge(adat, bdat, cdat, ddat, by = "id")
# Do not show output on the console
df.merge(adat, bdat, cdat, ddat, by = "id", output = FALSE)
adat <- data.frame(id = c(1, 2, 3),
x1 = c(7, 3, 8))
bdat <- data.frame(id = c(1, 2),
x2 = c(5, 1))
cdat <- data.frame(id = c(2, 3),
y3 = c(7, 9))
ddat <- data.frame(id = 4,
y4 = 6)
# Example 1: Merge adat, bdat, cdat, and data by the variable id
df.merge(adat, bdat, cdat, ddat, by = "id")
# Example 2: Do not show output on the console
df.merge(adat, bdat, cdat, ddat, by = "id", output = FALSE)
if (FALSE) {
#-------------------------------------------------------------------------------
# Error messages
adat <- data.frame(id = c(1, 2, 3),
x1 = c(7, 3, 8))
bdat <- data.frame(code = c(1, 2, 3),
x2 = c(5, 1, 3))
cdat <- data.frame(id = factor(c(1, 2, 3)),
x3 = c(5, 1, 3))
ddat <- data.frame(id = c(1, 2, 2),
x2 = c(5, 1, 3))
edat <- data.frame(id = c(1, NA, 3),
x2 = c(5, 1, 3))
fdat <- data.frame(id = c(1, 2, 3),
x1 = c(5, 1, 3))
# Error 1: Data frames do not have the same matching variable specified in 'by'.
df.merge(adat, bdat, by = "id")
# Error 2: Matching variable in the data frames do not all have the same class.
df.merge(adat, cdat, by = "id")
# Error 3: There are duplicated values in the matching variable specified in 'by'.
df.merge(adat, ddat, by = "id")
# Error 4: There are missing values in the matching variable specified in 'by'.
df.merge(adat, edat, by = "id")
# Error 5: There are duplicated variable names across data frames.
df.merge(adat, fdat, by = "id")
}
Run the code above in your browser using DataLab