Levels: Levels of a factor or unique values of a vector

View source: R/Levels.R

LevelsR Documentation

Levels of a factor or unique values of a vector

Description

Useful as an argument to lapply

Usage

Levels(x, na.rm = TRUE)

Arguments

x

vector

na.rm

(default TRUE) remove NAs if x is not a factor, otherwise just return levels(x)

Examples

## Not run: 
head(hs)
fits <- lapply(Levels(hs$school), function(sid)
           lm(mathach ~ ses, subset(hs, school == sid)))
coefs <- lapply(fits, coefs)
df <- do.call(rbind, coefs)
df$school <- names(df)

## End(Not run)

gmonette/spida2 documentation built on Aug. 11, 2024, 7:52 p.m.