Learn R Programming

expss (version 0.10.7)

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 cro_* 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

x %merge% y

Arguments

x

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

y

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

Value

data.frame

See Also

fre, cro, cro, cro_fun, merge

Examples

Run this code
# NOT RUN {
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 = calculate(mtcars, cro_cpct(gear, am))
# table with percents
tab2 = calculate(mtcars, cro_cpct(gear, vs))

# combine tables
tab1 %merge% tab2

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

# combine tables
counts %merge% percents
# }

Run the code above in your browser using DataLab