Skip to contents

Calculate the mean value per time point

Usage

mean_val_per_timepoint(data, time_col, val_col)

Arguments

data

The data.frame to be used for the calculation.

It should contain a column with the values to be summarized, and the corresponding time points denoting when the measurement was taken.

Zero-value entries are ignored and are completely removed from the calculation, unless every value corresponding to the time point is zero.

time_col

string Name of the column containing the time data.

val_col

string Name of the column containing the values to summarize.

Value

A tibble containing the mean value for each individual time point. The data frame contains two columns - the original time_col column and the calculated mean value column in the format Mean_[val_col].

Examples

x <- data.frame(
         days_from_baseline = c(0, 0, 0, 27, 27),
         MAF = c(0, 0.009, 0.007, 0.012, 0.032))

mean_val_per_timepoint(x, 'days_from_baseline', 'MAF')
#> # A tibble: 2 × 2
#>   days_from_baseline Mean_MAF
#>                <dbl>    <dbl>
#> 1                  0    0.008
#> 2                 27    0.022