| vmr_stack | R Documentation |
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.
vmr_stack(data, col, names_to = "level")
data |
a tibble |
col |
the name of a multiple-response column in |
names_to |
the desired output name of the variable with the stacked levels |
An expanded data frame
mr_stack
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")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.