R/transmute.R

Defines functions transmute

Documented in transmute

#' Add new variables and drop all others
#'
#' @description
#' Unlike `mutate()`, `transmute()` keeps only the variables that you create
#'
#' @param .df A data.frame or data.table
#' @param ... Columns to create/modify
#' @param .by Columns to group by
#'
#' @export
#'
#' @examples
#' df <- data.table(
#'   a = 1:3,
#'   b = 4:6,
#'   c = c("a", "a", "b")
#' )
#'
#' df %>%
#'   transmute(double_a = a * 2)
transmute <- function(.df, ..., .by = NULL) {
  mutate(.df, ..., .by = {{ .by }}, .keep = "none")
}

Try the tidytable package in your browser

Any scripts or data that you put into this service are public.

tidytable documentation built on Sept. 11, 2024, 8:05 p.m.