derive_metric: Derive tidycyte metric using arithmetic or function

Description Usage Arguments Value Examples

View source: R/derive_metric.R

Description

Permits the use of arithmetic or other R functions for each metric. Can accept other metrics in arguments.

Usage

1
derive_metric(.df, .name, .formula)

Arguments

.df

A data frame containing tidycyte data.

.name

<data-masking> The masked name of the metric to be derived (can overwrite existing metrics)

.formula

<data-masking> A formula containing masked metric names. May use arithmetic or other R functions, and can make use of other metrics.

Value

An updated data frame containing the new or revised metric.

Examples

1
2
3
4
5
df %>% derive_metric(Yellow, sqrt(`h2-3`) / mAzalea^2 - 3) # mathematical operations and offsets
df %>% derive_metric(mAzalea, mAzalea - mean(mAzalea)) # can use other functions
df %>% derive_metric(mAzalea, mAzalea - as.numeric(quantile(mAzalea,0.05))) # minus bottom 5%ile
df %>% derive_metric(mAzalea_scaled, mAzalea) %>% # copy to new name rather than the original name
  scale_metric(mAzalea_scaled) # rescale from 0 to 1 by default, returns the same name

hodgeslab/tidycyte documentation built on Dec. 20, 2021, 4:47 p.m.