Created
February 19, 2019 15:26
-
-
Save brshallo/4cf343686e92acc4f57cda7aa9b7f331 to your computer and use it in GitHub Desktop.
Function to add multiple inputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(purrr) | |
add_vecs <- function(...){ | |
if(!is.list(...)) stop("must be list input") | |
reduce(..., `+`) | |
} | |
add_vecs(list(1:5, 1:5, 1:5)) | |
#> [1] 3 6 9 12 15 | |
<sup>Created on 2019-02-15 by the [reprex package](https://reprex.tidyverse.org) (v0.2.1)</sup> | |
# Apply to dataframe | |
iris %>% | |
mutate(sum_lengths = select(., contains("Length")) %>% add_vecs()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment