Comment

Comment by tmoertel

If it is "cursed" for a function to do what it is clearly documented to do, instead of what someone mistakenly imagines it to do, then what function isn't cursed?

> Not being able to specify how ties are handled (and choosing, as far as I can tell, a fairly useless definition) fits the bill.

Actually, you can completely specify how ties are handled—and should, in any study designed to be repeatable. The docs for dplyr::ntile tell us that:

> To rank by multiple columns at once, supply a data frame.

So, repeatable, completely specified tiebreaking is as easy as adding a tiebreaker column to the dataset, using whatever strategy makes sense for your study. For example, if we wanted random tiebreaking using R's built-in `runif`, all it takes is one extra line of code:

    data_table |>
      dplyr::mutate(
        tie_breaker = runif(dplyr::n()),
        ntile_bin = dplyr::ntile(tibble::tibble(partitioning_key, tie_breaker), n = 4))
Almost 100% of the original author's problems could have been avoided by just reading the docs.
parent tmoertel 1 month ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton