extract-methods: Subset a huxtable

[.huxtableR Documentation

Subset a huxtable

Description

Subset a huxtable

Usage

## S3 method for class 'huxtable'
x[i, j, drop = FALSE]

## S3 replacement method for class 'huxtable'
x[i, j] <- value

## S3 replacement method for class 'huxtable'
x$name <- value

## S3 replacement method for class 'huxtable'
x[[i, j]] <- value

Arguments

x

A huxtable.

i

Rows to select.

j, name

Columns to select.

drop

Only included for compatibility with ⁠[.data.frame⁠. Do not use.

value

A matrix, data frame, huxtable or similar object.

Value

[ returns a huxtable. $ and [[ return data from the underlying data frame.

Replacing existing rows and columns

For the replacement function ⁠[<-⁠, if value is a huxtable, then its properties will be copied into x. Replacement functions ⁠$<-⁠ and ⁠[[<-⁠ replace existing data without affecting any properties.

Adding new rows and columns

If new columns or rows are created, then properties will be copied from the last column or row of x, or from value if value is a huxtable.

These methods are stricter than their data frame equivalents in some places. You can't add new rows or column at a numeric location without specifying all intervening rows/columns. New values must have the appropriate dimensions (vectors will be interpreted appropriately).

Examples

jams[1:3, ]
class(jams[1:3, ])
jams[, 1]
jams$Type
prices <- huxtable(c("Price", 1.70, 2.00, 2.20))
number_format(prices) <- 2
bold(prices) <- TRUE
jams[, 2] <- prices
jams

data(jams)
jams$price <- c("Price", 1.70, 2.00, 2.20)
jams

hughjonesd/huxtable documentation built on Feb. 17, 2024, 12:20 a.m.