nsub: Number of Subjects

View source: R/nsub.r

nsubR Documentation

Number of Subjects

Description

Function to compute the number of subjects.

Usage

nsub(id, data)

Arguments

id

vector to specify a subject id variable.

data

optional data frame that contains the variable specified above.

Details

The function simply computes the number of subjects in a long-format dataset (i.e., the number of unique values of the id variable).

Value

A scalar.

Author(s)

Wolfgang Viechtbauer wvb@wvbauer.com

Examples

# illustrative dataset
dat <- data.frame(subj=rep(1:4, each=5),
                  obs = 1:5,
                  age = rep(c(20,31,27,22), each=5),
                  stress = c(2,3,NA,4,2, 3,3,NA,3,NA, 1,1,2,6,4, 1,2,1,3,1))
dat

# compute the number of subjects
nsub(subj, dat)

# or specify the subject variable this way
nsub(dat$subj)

wviechtb/esmpack documentation built on April 12, 2025, 9:48 p.m.