samba: Mutate new columns

Description Usage Arguments Examples

View source: R/mutate.R

Description

Applies the ballet() and makes sure each result have the same vctrs::vec_size() as the number of elements in each group.

Usage

1
2
3
4
5
6
7
salsa(.tbl, ..., .env = caller_env())

chacha(.tbl)

samba(.tbl, ..., .env = caller_env())

madison(.tbl, ..., .name = "data", .env = caller_env())

Arguments

.tbl

A data frame, most likely a grouped data frame

..., .env

formulas for each column to create, and parent environment, see ballet()

.name

Name of the packed column made by charleston()

The four functions play a separate role around the idea of dplyr::mutate():

  • chacha() reorganizes the rows of a grouped data frame so that data for each group is contiguous in each column.

  • salsa() runs the ballet() defined by ... and makes sure the vctrs::vec_size() of each result is equal to the number of elements in that group. The result tibble of salsa() does not contain the grouping variables, just those columns specified by the ....

  • samba() is the closest to dplyr::mutate(), it column binds the result of chacha() and salsa() with vctrs::vec_cbind().

  • madison() is similar to sambda() but the results are packed instead of being [vctrs::vec_cbind()]. The name of the created packed column is controled by the .name argument.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
g <- group_by(iris, Species)

# Creates a `dance_grouped_df` tibble,
# which is the same as `g` but guarantees that the data for each column
# is contiguous within groups
chacha(g)

# returns a tibble of two columns
g %>%
  salsa(
    Sepal = ~Sepal.Length * Sepal.Width,
    Petal = ~Petal.Length * Petal.Width
  )

# returns a dance_grouped_df with the two
# additional columns `Sepal` and `Petal`
g %>%
  samba(
    Sepal = ~Sepal.Length * Sepal.Width,
    Petal = ~Petal.Length * Petal.Width
  )

# returns a dance_grouped_df with the one
# additional data frame column
g %>%
  madison(
    Sepal = ~Sepal.Length * Sepal.Width,
    Petal = ~Petal.Length * Petal.Width
  )

romainfrancois/dance documentation built on Nov. 21, 2019, 11:49 a.m.