Adds or updates columns in data.frame.

mutate_dt(.data, ..., by)

transmute_dt(.data, ..., by)

Arguments

.data

data.frame

...

List of variables or name-value pairs of summary/modifications functions.

by

(Optional) Mutate by what group?

Value

data.table

See also

Examples


iris %>% mutate_dt(one = 1,Sepal.Length = Sepal.Length + 1)
#>      Sepal.Length Sepal.Width Petal.Length Petal.Width   Species   one
#>             <num>       <num>        <num>       <num>    <fctr> <num>
#>   1:          6.1         3.5          1.4         0.2    setosa     1
#>   2:          5.9         3.0          1.4         0.2    setosa     1
#>   3:          5.7         3.2          1.3         0.2    setosa     1
#>   4:          5.6         3.1          1.5         0.2    setosa     1
#>   5:          6.0         3.6          1.4         0.2    setosa     1
#>  ---                                                                  
#> 146:          7.7         3.0          5.2         2.3 virginica     1
#> 147:          7.3         2.5          5.0         1.9 virginica     1
#> 148:          7.5         3.0          5.2         2.0 virginica     1
#> 149:          7.2         3.4          5.4         2.3 virginica     1
#> 150:          6.9         3.0          5.1         1.8 virginica     1
iris %>% transmute_dt(one = 1,Sepal.Length = Sepal.Length + 1)
#>        one Sepal.Length
#>      <num>        <num>
#>   1:     1          6.1
#>   2:     1          5.9
#>   3:     1          5.7
#>   4:     1          5.6
#>   5:     1          6.0
#>  ---                   
#> 146:     1          7.7
#> 147:     1          7.3
#> 148:     1          7.5
#> 149:     1          7.2
#> 150:     1          6.9
# add group number with symbol `.GRP`
iris %>% mutate_dt(id = 1:.N,grp = .GRP,by = Species)
#>      Sepal.Length Sepal.Width Petal.Length Petal.Width   Species    id   grp
#>             <num>       <num>        <num>       <num>    <fctr> <int> <int>
#>   1:          5.1         3.5          1.4         0.2    setosa     1     1
#>   2:          4.9         3.0          1.4         0.2    setosa     2     1
#>   3:          4.7         3.2          1.3         0.2    setosa     3     1
#>   4:          4.6         3.1          1.5         0.2    setosa     4     1
#>   5:          5.0         3.6          1.4         0.2    setosa     5     1
#>  ---                                                                        
#> 146:          6.7         3.0          5.2         2.3 virginica    46     3
#> 147:          6.3         2.5          5.0         1.9 virginica    47     3
#> 148:          6.5         3.0          5.2         2.0 virginica    48     3
#> 149:          6.2         3.4          5.4         2.3 virginica    49     3
#> 150:          5.9         3.0          5.1         1.8 virginica    50     3