add_l2: Add level-2 data to an scdf

View source: R/add_l2.R

add_l2R Documentation

Add level-2 data to an scdf

Description

Merges variables with corresponding case names from a data.frame with an scdf.

Usage

add_l2(scdf, data_l2, cvar = "case")

Arguments

scdf

A single-case data frame. See scdf() to learn about this format.

data_l2

A level 2 dataset.

cvar

Character string with the name of the "case" variable in the L2 dataset (default is 'case').

Details

This function is mostly used in combination with the hplm() function. It adds level-2 variables to each single-case data frame in an scdf based on matching case names.

Value

An scdf with added level-2 variables.

Author(s)

Juergen Wilbert

See Also

hplm()

Other data manipulation functions: as.data.frame.scdf(), as_scdf(), batch_apply(), fill_missing(), moving_median(), print.sc_outlier(), ranks(), rescale(), scdf(), select_cases(), set_vars(), shift(), smooth_cases(), standardize(), truncate_phase()

Examples

## Example with the default case variable name 'case'
Leidig2018 |> add_l2(Leidig2018_l2)
## Example with a different case variable name in the L2 data
Leidig2018_l2_renamed <- Leidig2018_l2
names(Leidig2018_l2_renamed)[2] <- "subject"
Leidig2018 |> add_l2(Leidig2018_l2_renamed, cvar = "subject")

scan documentation built on April 1, 2026, 9:06 a.m.