row_sums: Apply simple rowwise functions

Description Usage Arguments Details Value Examples

View source: R/row_sums.R

Description

Get means, sums and possibly other functions for a select number of columns using dplyr::select-style column selection.

Usage

1
2
3
4
5
6
7
8
9
row_sums(data, ..., na_rm = FALSE, varname = "sum")

row_means(data, ..., na_rm = FALSE, varname = "mean")

row_min(data, ..., na_rm = FALSE, varname = "min")

row_max(data, ..., na_rm = FALSE, varname = "max")

row_apply(data, ..., .fun, varname = "var")

Arguments

data

A data frame.

...

The columns to sum, take the mean of, etc. Required.

na_rm

Whether to remove NA values or not. Default is FALSE.

varname

The column name of the sums means etc. as a character string.

.fun

The function to apply.

Details

Simple wrappers for applying rowwise operations only for selected columns within the tidyverse approach to data processing. The row_apply function requires a function that already works on rows.

Value

A data frame with a new column representing the sums, means or whatever.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
library(tidyext)
library(dplyr)

d = data.frame(x = 1:3, y = 4:6, z = 7:9)

d  %>%
  row_sums(x:y)

d  %>%
  row_means(matches('x|z'))

d  %>%
  row_max(matches('x|y'))

row_apply(
  d ,
  everything(),
  .fun = function(x)
    apply(x, 1, paste, collapse = '')
)

m-clark/tidyext documentation built on July 21, 2020, 2:36 a.m.