subsetting_wlevels: Extraction Methods for a 'wlevels'-class Object

subsetting_wlevelsR Documentation

Extraction Methods for a 'wlevels'-class Object

Description

For subsetting a 'wlevels'-class object. Attributes related to the levels will be preserved if appropriate.

Usage

## S3 method for class 'wlevels'
x[i, j, drop = if (missing(i)) TRUE else length(j) == 1]

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

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

Arguments

x

A 'wlevels'-class object.

i

A numeric vector of row number(s), a character vector of row name(s), or a logical vector of row(s) to be selected.

j

A numeric vector of column number(s), a character vector of column name(s), or a logical vector of column(s) to be selected.

drop

Whether dropping a dimension if it only have one row/column.

value

Ignored.

Details

Customized [ for 'wlevels'-class objects, to ensure that these operations work as they would be on a data frame object, while information specific to a wlevels-class object modified correctly.

The assignment methods ⁠[<-⁠ and ⁠[[<-⁠ for wlevels-class objects will raise an error. This class of objects should be created by mod_levels() or related functions.

Subsetting the output of mod_levels() is possible but not recommended. It is more reliable to generate the levels using mod_levels() and related functions. Nevertheless, there are situations in which subsetting is preferred.

Value

A 'wlevels'-class object. See mod_levels() and merge_mod_levels() for details on this class.

See Also

mod_levels(), mod_levels_list(), and merge_mod_levels()

Examples


data(data_med_mod_ab)
dat <- data_med_mod_ab
# Form the levels from a list of lm() outputs
lm_m <- lm(m ~ x*w1 + c1 + c2, dat)
lm_y <- lm(y ~ m*w2 + x + w1 + c1 + c2, dat)
lm_out <- lm2list(lm_m, lm_y)
w1_levels <- mod_levels(lm_out, w = "w1")
w1_levels
w1_levels[2, ]
w1_levels[c(2, 3), ]

dat <- data_med_mod_serial_cat
lm_m1 <- lm(m1 ~ x*w1 + c1 + c2, dat)
lm_y <- lm(y ~ m1 + x + w1 + c1 + c2, dat)
lm_out <- lm2list(lm_m1, lm_y)
w1gp_levels <- mod_levels(lm_out, w = "w1")
w1gp_levels
w1gp_levels[2, ]
w1gp_levels[3, ]

merged_levels <- merge_mod_levels(w1_levels, w1gp_levels)
merged_levels

merged_levels[4:6, ]
merged_levels[1:3, c(2, 3)]
merged_levels[c(1, 4, 7), 1, drop = FALSE]


manymome documentation built on Oct. 4, 2024, 5:10 p.m.