scale_metric: Scale tidycyte metric

Description Usage Arguments Details Value Examples

View source: R/scale_metric.R

Description

Convenience function that uses derive_metric() and the scales::rescale() function. By default, rescales each individual measured value from 0 to 1 using the range from minmum to maximum value.

Usage

1
scale_metric(.df, .name, .to = c(0, 1), ...)

Arguments

.df

A data frame containing tidycyte data.

.name

<data-masking> The masked name of the metric to normalize.

.to

Numeric vector of the min and max final rescaled range. Defaults to c(0,1).

...

<dynamic-dots> Additional arguments to pass to rescale().

Details

Note that this does not scale according to the mean of the observations but to the individual measured values themselves. Hence if using summary_stats(), the maximum mean value would be expected to be less than 1. If normalization is needed after using summary_stats(), it can be performed manually.

This function overwrites the original metric. If a new metric name is desired, the original metric should first be copied to a new metric name. See example below.

Value

A dataframe with rescaled metrics

Examples

1
2
3
4
5
6
# copy to new name rather than the original name
df %>% derive_metric(mAzalea_scaled, mAzalea) %>% 
  scale_metric(mAzalea_scaled)

# rescales mAzalea metric in place, overwriting original values
df %>% scale_metric(mAzalea)

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