Skip to content

Instantly share code, notes, and snippets.

@plpxsk
Last active March 9, 2017 00:18
Show Gist options
  • Save plpxsk/70a757315901447703ce7ae4254a8407 to your computer and use it in GitHub Desktop.
Save plpxsk/70a757315901447703ce7ae4254a8407 to your computer and use it in GitHub Desktop.
Examples of new `dplyr` and `purrr` functionality
library(tibble)
library(dplyr)
## sample data
df <- frame_data(
~x, ~y, ~z, ~x1, ~x2, ~x3, ~y1, ~y2, ~y99, ~z99, ~zz,
99, 2, 3.6, 99, 2, 3.6, 99, 2, 3.6, 99, 2,
99, 2, 3.6, 99, 2, 3.6, 99, 2, 3.6, 99, 2,
99, 2, 3.6, 99, 2, 3.6, 99, 2, 3.6, 99, 2
)
## Example: divide each column by 100
df %>% mutate_all(funs("div_by_100" = . / 100)) %>% glimpse
## Example: subtract one column from all others
df %>% mutate_all(funs("minus_x" = . - x)) %>% glimpse
## More coming soon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment