| scale_at | R Documentation |
multiply_at() and divide_at() avoid one of the pitfalls of
mutate_at(), which is that mutate_at() applies transformations
sequentially, rather than in parallel. See Details, below.
multiply_at(...)
divide_at(...)
.tbl |
tabular data |
.vars |
A list of columns generated by |
by |
a value or expression, to be evaluated within |
Suppose we want to "normalize" all columns by the values in one column. The following code doesn't yield that result:
mtcars %>% mutate_at(vars(everything()), ~ 1 / wt)
All columns after wt are left "untouched". Why?
What's happening is that the columns are being transformed sequentially,
rather than in parallel. First mpg is divided by wt. Then, cyl is
divided by wt, followed by disp, hp, and drat.
Next, wt is divided by wt. From this point on, wt is equal to 1.
When the next column, qsec, is divided by wt, it's just being divided
by 1. And so on for vs, am, gear, and carb. The values in those
columns remain the same.
multiply_at: multiplication
divide_at: division
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.