huxtable (version 4.6.1)

add_rows: Insert one matrix into another.

Description

These functions combine two matrix-like objects and return the result.

Usage

add_rows(x, y, after = nrow(x), ...)

add_columns(x, y, after = ncol(x), ...)

Arguments

x

A matrix-like object, e.g. a huxtable

y

Matrix or vector to be inserted into x

after

Row or column after which y is inserted. Can be 0. Can be a row or column name. By default, inserts y after the end of x.

...

Arguments passed to rbind() or cbind()

Value

For add_rows, the result of rbind(x[1:after,], y, x[-(1:after),]. For add_columns the same but with columns. after = 0 and after = nrow(x) or ncol(x) are handled correctly.

Details

For huxtable objects, arguments in ... can include copy_cell_props.

See Also

insert_row() and insert_column(), which insert multiple values into a single row.

Examples

Run this code
# NOT RUN {
ht <- hux(
        Jam = c("Raspberry", "Plum"),
        Price = c(1.90, 1.80),
        add_colnames = TRUE
      )

ht2 <- hux("Gooseberry", 2.10)
add_rows(ht, ht2)
add_rows(ht, ht2, after = 1)

mx <- matrix(
      c("Sugar", "50%", "60%",
      "Weight (g)", 300, 250),
      3, 2)
add_columns(ht, mx, after = "Jam")
# }

Run the code above in your browser using DataCamp Workspace