split_by {edibble}R Documentation

Split or count the data according to certain factors

Description

This function has a similar result with split() where it returns a named list with names corresponding to the levels of the separating factor (or concatenated strings if multiple separating factors). The key differences to split(), are that the splitting factor does not appear in the elements of the list and only linked factors and their ancestors appear in the output, e.g. if treatment is applied to wholeplot and subplots are nested within subplots, then the subplot will not be shown in the output if split by treatment.

Usage

split_by(.data, ..., .sep = ":", .remove_empty = TRUE)

count_by(.data, ..., .remove_empty = TRUE)

Arguments

.data

An edibble table.

...

The factors to split or count by. You cannot split by a record factor or a factor that uniquely indexes the smallest unit in the design. You cannot also combine treatment and unit factors together.

.sep

The separator to use if more than one factor to split by.

.remove_empty

Remove empty combinations. Default is TRUE.

Value

A named list.

See Also

pivot_wider_by()

Examples

spd <- takeout(menu_split())
split(spd, spd$trt1)
spd %>% split_by(trt1)
spd %>% split_by(trt2)
spd %>% split_by(mainplot)
spd %>% count_by(trt1)

fac <- takeout(menu_factorial(trt = c(2, 2, 2)))
fac %>% count_by(where(~is_trt(.x)))


[Package edibble version 1.1.0 Index]