Learn R Programming

expss (version 0.5.5)

add_rows: Add rows to data.frame/matrix/table

Description

add_rows is similar to rbind but it handles non-matching column names. %add_rows% is an infix version of add_rows. There is also special method for the results of cro_*/fre. .add_rows is version for addding rows to default dataset. See default_dataset.

Usage

add_rows(...)
"add_rows"(..., nomatch_columns = c("add", "drop", "stop"))
x %add_rows% y
.add_rows(..., nomatch_columns = c("add", "drop", "stop"))

Arguments

...
data.frame/matrix/table for binding
nomatch_columns
action if there are non-matching columns between data.frames. Possible values are "add", "drop", "stop". "add" will combine all columns, "drop" will leave only common columns, "stop" will raise an error.
x
data.frame/matrix/table for binding
y
data.frame/matrix/table for binding

Value

See rbind, cro, fre

Examples

Run this code
a = data.frame(x = 1:5, y = 6:10)
b = data.frame(y = 6:10, z = 11:15)

add_rows(a, b) # x, y, z
a %add_rows% b # the same result

add_rows(a, b, nomatch_columns = "drop")  # y

# simple tables
data(mtcars)

mtcars = modify(mtcars, {
            var_lab(mpg) = "Miles/(US) gallon"
            var_lab(vs) = "vs"
            val_lab(vs) = c("V-engine" = 0, "Straight engine" = 1)
            var_lab(am) = "am"
            val_lab(am) = c("automatic transmission" = 1, "manual transmission" = 0)
            var_lab(gear) = "gear"
            var_lab(carb) = "carb"
})

tab_mean = with(mtcars, cro_mean(mpg, am))
tab_percent = with(mtcars, cro_cpct(vs, am))

tab_mean %add_rows% tab_percent

Run the code above in your browser using DataLab