du_add_margin: Add margins considering all numeric values in a data frame

Description Usage Arguments Details Value Examples

View source: R/table_info.R

Description

Adding margins to column, row or both, non-numeric columns are ignored.Use argument ingnoreCols to skip numeric columns.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
du_add_margin(
  df,
  margin = "both",
  verbose = TRUE,
  ignore_columns = NULL,
  enable_total_margin = TRUE,
  direction_total_margin = "column",
  fun.aggregate = sum,
  ...
)

Arguments

df

data frame to add margin to.

margin

valid values are "column", "row", "both". Append margins after column, row or both.

verbose

show or hide messages

enable_total_margin

default to TRUE, whether to calcualte total margin when margin = "both"

direction_total_margin,

default to "column", direction for calculating total margin, please read more in details.

fun.aggregate

function used to calculate margin, default to sum, can be one of min, max, median, sd, sum, mean or any other custom functions which can reduce a column/row automatically enabled.

...

other arguments passed to aggregate function

ingnoreCols

numeric columns to ignore when adding margin, can use column names or column indexes.

Details

when direction is set to "both", total margin on bottom right of the data frame may not make sense when using mean, sd or similar functions as aggregating fucntion.

To specify direction of calculation: direction_total_margin = "column" to calculate by columns(horizontally), direction_total_margin = "row" to calculate by rows(vertically)

Value

A data frame with extra an extra column/row as the total for that column/row

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
du_add_margin(iris)
du_add_margin(iris,verbose = FALSE)
du_add_margin(iris,fun.aggregate=mean,na.rm = TRUE)
# disable calculation for total margin
du_add_margin(
  iris,
  enable_total_margin = FALSE,
  fun.aggregate=sd,
  na.rm = TRUE
)

yusuzech/dfutils documentation built on Dec. 8, 2019, 4:39 p.m.