apply_row | R Documentation |
apply_row()
is a wrapper around apply()
and select()
,
applying a function rowwise, and selecting variables with dplyr::select() syntax.
This makes code slightly less verbose for rowwise operations.
apply_row(x, select_helpers = everything(), FUN, ...)
x |
Data frame or tibble to pass through. |
select_helpers |
Select variables using dplyr::select() syntax |
FUN |
Function to be applied to selected columns |
... |
Additional arguments to the function. |
## Not run:
library(tidyverse)
iris %>% mutate(Sepal_Sum = apply_row(.,select_helpers = contains("Sepal"), sum, na.rm = TRUE))
iris %>% mutate(Sepal_Sum = apply_row(.,c("Sepal.Length","Petal.Width"), function(x) sum(x > 1)))
Can use a character vector to select columns
petal_str <- c("Petal.Length", "Petal.Width")
iris %>% mutate(Any_Petal = apply_row(., petal_str, function(x) any(x > 1)))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.