Mutate multiple columns
Usage
mutateAll(object, fun, ...)
mutateAll(object, fun, ...)
mutateIf(object, predicate, fun, ...)
transmuteAt(object, vars, fun, ...)
transmuteIf(object, predicate, fun, ...)
# S4 method for DFrame,`function`
mutateAll(object, fun, ...)
# S4 method for DFrame,character,`function`
mutateAt(object, vars, fun, ...)
# S4 method for DFrame,`function`,`function`
mutateIf(object, predicate, fun, ...)
# S4 method for DFrame,character,`function`
transmuteAt(object, vars, fun, ...)
# S4 method for DFrame,`function`,`function`
transmuteIf(object, predicate, fun, ...)
Arguments
- object
Object.
- fun
function
. Mutation function.- ...
Passthrough arguments to function declared in
fun
argument.- vars
character
. Column names.- predicate
function
. A predicate function to be applied to the columns. For example,is.atomic()
.
See also
These functions are inspired by dplyr. However, they are designed to only work on Bioconductor S4 class objects, and use base R code internally.
Examples
data(mtcars, package = "datasets")
## DFrame ====
x <- as(mtcars, "DFrame")
mutateAll(x, fun = log, base = 2L)
#> DataFrame with 32 rows and 11 columns
#> mpg cyl disp hp drat wt
#> <numeric> <numeric> <numeric> <numeric> <numeric> <numeric>
#> Mazda RX4 4.39232 2.58496 7.32193 6.78136 1.96347 1.38957
#> Mazda RX4 Wag 4.39232 2.58496 7.32193 6.78136 1.96347 1.52356
#> Datsun 710 4.51096 2.00000 6.75489 6.53916 1.94486 1.21412
#> Hornet 4 Drive 4.41954 2.58496 8.01123 6.78136 1.62293 1.68482
#> Hornet Sportabout 4.22497 3.00000 8.49185 7.45121 1.65535 1.78241
#> ... ... ... ... ... ... ...
#> Lotus Europa 4.92600 2.00000 6.57137 6.82018 1.91456 0.597412
#> Ford Pantera L 3.98185 3.00000 8.45533 8.04439 2.07724 1.664483
#> Ferrari Dino 4.30012 2.58496 7.17991 7.45121 1.85599 1.469886
#> Maserati Bora 3.90689 3.00000 8.23362 8.38802 1.82375 1.835924
#> Volvo 142E 4.41954 2.00000 6.91886 6.76818 2.03914 1.475085
#> qsec vs am gear carb
#> <numeric> <numeric> <numeric> <numeric> <numeric>
#> Mazda RX4 4.04089 -Inf 0 2.00000 2
#> Mazda RX4 Wag 4.08916 -Inf 0 2.00000 2
#> Datsun 710 4.21801 0 0 2.00000 0
#> Hornet 4 Drive 4.28096 0 -Inf 1.58496 0
#> Hornet Sportabout 4.08916 -Inf -Inf 1.58496 1
#> ... ... ... ... ... ...
#> Lotus Europa 4.07895 0 0 2.32193 1.00000
#> Ford Pantera L 3.85798 -Inf 0 2.32193 2.00000
#> Ferrari Dino 3.95420 -Inf 0 2.32193 2.58496
#> Maserati Bora 3.86790 -Inf 0 2.32193 3.00000
#> Volvo 142E 4.21723 0 0 2.00000 1.00000
mutateAt(x, vars = c("mpg", "cyl"), fun = log, base = 2L)
#> DataFrame with 32 rows and 11 columns
#> mpg cyl disp hp drat wt
#> <numeric> <numeric> <numeric> <numeric> <numeric> <numeric>
#> Mazda RX4 4.39232 2.58496 160 110 3.90 2.620
#> Mazda RX4 Wag 4.39232 2.58496 160 110 3.90 2.875
#> Datsun 710 4.51096 2.00000 108 93 3.85 2.320
#> Hornet 4 Drive 4.41954 2.58496 258 110 3.08 3.215
#> Hornet Sportabout 4.22497 3.00000 360 175 3.15 3.440
#> ... ... ... ... ... ... ...
#> Lotus Europa 4.92600 2.00000 95.1 113 3.77 1.513
#> Ford Pantera L 3.98185 3.00000 351.0 264 4.22 3.170
#> Ferrari Dino 4.30012 2.58496 145.0 175 3.62 2.770
#> Maserati Bora 3.90689 3.00000 301.0 335 3.54 3.570
#> Volvo 142E 4.41954 2.00000 121.0 109 4.11 2.780
#> qsec vs am gear carb
#> <numeric> <numeric> <numeric> <numeric> <numeric>
#> Mazda RX4 16.46 0 1 4 4
#> Mazda RX4 Wag 17.02 0 1 4 4
#> Datsun 710 18.61 1 1 4 1
#> Hornet 4 Drive 19.44 1 0 3 1
#> Hornet Sportabout 17.02 0 0 3 2
#> ... ... ... ... ... ...
#> Lotus Europa 16.9 1 1 5 2
#> Ford Pantera L 14.5 0 1 5 4
#> Ferrari Dino 15.5 0 1 5 6
#> Maserati Bora 14.6 0 1 5 8
#> Volvo 142E 18.6 1 1 4 2
mutateIf(x, predicate = is.double, fun = as.integer)
#> DataFrame with 32 rows and 11 columns
#> mpg cyl disp hp drat wt
#> <integer> <integer> <integer> <integer> <integer> <integer>
#> Mazda RX4 21 6 160 110 3 2
#> Mazda RX4 Wag 21 6 160 110 3 2
#> Datsun 710 22 4 108 93 3 2
#> Hornet 4 Drive 21 6 258 110 3 3
#> Hornet Sportabout 18 8 360 175 3 3
#> ... ... ... ... ... ... ...
#> Lotus Europa 30 4 95 113 3 1
#> Ford Pantera L 15 8 351 264 4 3
#> Ferrari Dino 19 6 145 175 3 2
#> Maserati Bora 15 8 301 335 3 3
#> Volvo 142E 21 4 121 109 4 2
#> qsec vs am gear carb
#> <integer> <integer> <integer> <integer> <integer>
#> Mazda RX4 16 0 1 4 4
#> Mazda RX4 Wag 17 0 1 4 4
#> Datsun 710 18 1 1 4 1
#> Hornet 4 Drive 19 1 0 3 1
#> Hornet Sportabout 17 0 0 3 2
#> ... ... ... ... ... ...
#> Lotus Europa 16 1 1 5 2
#> Ford Pantera L 14 0 1 5 4
#> Ferrari Dino 15 0 1 5 6
#> Maserati Bora 14 0 1 5 8
#> Volvo 142E 18 1 1 4 2
transmuteAt(x, vars = c("mpg", "cyl"), fun = log, base = 2L)
#> DataFrame with 32 rows and 2 columns
#> mpg cyl
#> <numeric> <numeric>
#> Mazda RX4 4.39232 2.58496
#> Mazda RX4 Wag 4.39232 2.58496
#> Datsun 710 4.51096 2.00000
#> Hornet 4 Drive 4.41954 2.58496
#> Hornet Sportabout 4.22497 3.00000
#> ... ... ...
#> Lotus Europa 4.92600 2.00000
#> Ford Pantera L 3.98185 3.00000
#> Ferrari Dino 4.30012 2.58496
#> Maserati Bora 3.90689 3.00000
#> Volvo 142E 4.41954 2.00000
transmuteIf(x, predicate = is.double, fun = as.integer)
#> DataFrame with 32 rows and 11 columns
#> mpg cyl disp hp drat wt
#> <integer> <integer> <integer> <integer> <integer> <integer>
#> Mazda RX4 21 6 160 110 3 2
#> Mazda RX4 Wag 21 6 160 110 3 2
#> Datsun 710 22 4 108 93 3 2
#> Hornet 4 Drive 21 6 258 110 3 3
#> Hornet Sportabout 18 8 360 175 3 3
#> ... ... ... ... ... ... ...
#> Lotus Europa 30 4 95 113 3 1
#> Ford Pantera L 15 8 351 264 4 3
#> Ferrari Dino 19 6 145 175 3 2
#> Maserati Bora 15 8 301 335 3 3
#> Volvo 142E 21 4 121 109 4 2
#> qsec vs am gear carb
#> <integer> <integer> <integer> <integer> <integer>
#> Mazda RX4 16 0 1 4 4
#> Mazda RX4 Wag 17 0 1 4 4
#> Datsun 710 18 1 1 4 1
#> Hornet 4 Drive 19 1 0 3 1
#> Hornet Sportabout 17 0 0 3 2
#> ... ... ... ... ... ...
#> Lotus Europa 16 1 1 5 2
#> Ford Pantera L 14 0 1 5 4
#> Ferrari Dino 15 0 1 5 6
#> Maserati Bora 14 0 1 5 8
#> Volvo 142E 18 1 1 4 2