1 Matching Annotations
  1. Jan 2019
    1. sum_to_one <- function(x, na.rm = FALSE) { x / sum(x, na.rm = na.rm) }

      Since the sum of x is the same across the input, couldn't you make the code less repetitive by assigning it to an intermediate variable?

      sum_to_one <- function(x, na.rm = FALSE) { y = sum(x, na.rm = na.rm) x / y }