library(tibble)
# Prepare iris data for use with dig()
d <- partition(iris, .breaks = 2)
# Call f() for each condition with support >= 0.5. The result is a list
# of strings representing the conditions.
dig(x = d,
f = function(condition) {
format_condition(names(condition))
},
min_support = 0.5)
# Create a more complex pattern object - a list with some statistics
res <- dig(x = d,
f = function(condition, support) {
list(condition = format_condition(names(condition)),
support = support)
},
min_support = 0.5)
print(res)
# Format the result as a data frame
do.call(rbind, lapply(res, as_tibble))
# Within each condition, evaluate also supports of columns starting with
# "Species"
res <- dig(x = d,
f = function(condition, support, pp) {
c(list(condition = format_condition(names(condition))),
list(condition_support = support),
as.list(pp / nrow(d)))
},
condition = !starts_with("Species"),
focus = starts_with("Species"),
min_support = 0.5,
min_focus_support = 0)
# Format the result as a tibble
do.call(rbind, lapply(res, as_tibble))
# For each condition, create multiple patterns based on the focus columns
res <- dig(x = d,
f = function(condition, support, pp) {
lapply(seq_along(pp), function(i) {
list(condition = format_condition(names(condition)),
condition_support = support,
focus = names(pp)[i],
focus_support = pp[[i]] / nrow(d))
})
},
condition = !starts_with("Species"),
focus = starts_with("Species"),
min_support = 0.5,
min_focus_support = 0)
# As res is now a list of lists, we need to flatten it before converting to
# a tibble
res <- unlist(res, recursive = FALSE)
# Format the result as a tibble
do.call(rbind, lapply(res, as_tibble))
Run the code above in your browser using DataLab