Learn R Programming

expss (version 0.11.4)

merge.etable: Merge two tables/data.frames

Description

%merge% is infix shortcut for base merge with all.x = TRUE and all.y = FALSE (left join). There is also special method for combining results of cross_* and fre. For them all = TRUE (full join). It allows make complex tables from simple ones. See examples. Strange result is possible if one or two arguments have duplicates in first column (column with labels).

Usage

# S3 method for etable
merge(
  x,
  y,
  by = 1,
  by.x = by,
  by.y = by,
  all = TRUE,
  all.x = all,
  all.y = all,
  sort = FALSE,
  suffixes = c("", ""),
  incomparables = NULL,
  ...
)

Value

data.frame

Arguments

x

data.frame or results of fre/cross_*/table_*

y

data.frame or results of fre/cross_*/table_*

by

for 'etable' object default is 1 (first column). For details see merge

by.x

For details see merge

by.y

For details see merge

all

For details see merge

all.x

For details see merge

all.y

For details see merge

sort

For details see merge

suffixes

For details see merge

incomparables

For details see merge

...

arguments to be passed to or from methods.

See Also

fre, cross_cpct, cross_fun, merge

Examples

Run this code
data(mtcars)
# apply labels
mtcars = apply_labels(mtcars,
                mpg = "Miles/(US) gallon",
                cyl = "Number of cylinders",
                disp = "Displacement (cu.in.)",
                hp = "Gross horsepower",
                drat = "Rear axle ratio",
                wt = "Weight (lb/1000)",
                qsec = "1/4 mile time",
                vs = "V/S",
                vs = c("V-engine" = 0, "Straight engine" = 1),
                am = "Transmission (0 = automatic, 1 = manual)",
                am = c(automatic = 0, manual = 1),
                gear = "Number of forward gears",
                carb = "Number of carburetors"
)

# table by 'am'
tab1 = cross_cpct(mtcars, gear, am)
# table with percents
tab2 = cross_cpct(mtcars, gear, vs)

# combine tables
tab1 %>% merge(tab2)

# complex tables
# table with counts
counts = cross_cases(mtcars, list(vs, am, gear, carb), list("Count"))
# table with percents
percents = cross_cpct(mtcars, list(vs, am, gear, carb), list("Column, %"))

# combine tables
counts %>% merge(percents)

Run the code above in your browser using DataLab