add_weighted_mean: Calculate the rowwise weighted mean for columns selected in...

Description Usage Arguments Examples

View source: R/rowwise.R

Description

Calculate the rowwise weighted mean for columns selected in data.frame

Usage

1
add_weighted_mean(.data, ..., .weights, .name = "weighted_mean", na.rm = TRUE)

Arguments

.data

data.frame

...

columns selected for rowwise 'sum' or 'mean' using 'tidyselect' grammar

.weights

weights corresponding columns selected in dataframe

.name

the name of new column

na.rm

whether to delete the missing value, 'TRUE' or 'FALSE'

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
df <- tribble(
  ~id, ~x, ~y, ~z, ~g,
  #--|--|--|--|--
  "a", 13.1, 14, 4, 1,
  "b", 11.2, 7, 5, 0,
  "c", 12.5, 10, 1, 0,
  "d", 20, 11, 3, 1
)


weights <- c(
  x = 0.25,
  y = 0.25,
  z = 0.25,
  g = 0.25
)

df %>% add_weighted_mean(x:g, .name = "wt_mean", .weights = weights)

perlatex/easyuse documentation built on April 14, 2020, 5:35 a.m.