test-code/transpose-turf.R

items_to_cols <- function(res) {

    res %>%
        pivot_longer(
            cols = matches("i")
        ) %>%
        mutate(name = 1) %>%
        filter(!is.na(value)) %>%
        pivot_wider(
            names_from = value,
            values_from = name,
            values_fill = list(name = 0)
        )

}

# this is still no good
items_to_cells <- function(res) {

    res %>%
        pivot_longer(cols = -c(combo, reach, freq, k)) %>%
        mutate(width = nchar(n_distinct(name))) %>%
        mutate(name = factor(name)) %>%
        filter(value == 1) %>%
        select(-value) %>%
        group_by(combo) %>%
        mutate(
            item = row_number(),
            item = str_pad(
                string = item,
                width = width,
                side = "left",
                pad = "0"
            ),
            item = paste0("i_", item)
        ) %>%
        ungroup() %>%
        select(-width) %>%
        pivot_wider(names_from = item, values_from = name)

}
ttrodrigz/onezero documentation built on May 9, 2023, 2:59 p.m.