vmr_stack: Stack a multiple response column in a tibble

View source: R/vec_mr.R

vmr_stackR Documentation

Stack a multiple response column in a tibble

Description

Similar to mr_stack, but it works on whole data frames rather than individual vectors, expanding a multiple-response variable to a factor with a record for each observed response. The algorithm is to convert the object to a logical matrix, pivot_longer, then filter on the logical value.

Usage

vmr_stack(data, col, names_to = "level")

Arguments

data

a tibble

col

the name of a multiple-response column in data

names_to

the desired output name of the variable with the stacked levels

Value

An expanded data frame

See Also

mr_stack

Examples

data(ethnicity)

if(require("tidyr",quietly=TRUE)){

 t<-tibble(a=LETTERS[1:6], e=as.vmr(ethnicity,na.rm=TRUE))
 t
 t |> vmr_stack(e,names_to="ethnicity")


}


tslumley/rimu documentation built on March 21, 2024, 5:58 a.m.