Skip to contents

Clean Data by Interpolating Missing Values

Usage

clean_data(data, n_trials, n_replicates)

Arguments

data

A data frame containing the dataset to be cleaned.

n_trials

The total number of rows in the dataset.

n_replicates

The total number of replicate columns in each row.

Value

A cleaned data frame with missing values interpolated.

Details

This function cleans a dataset by interpolating missing values in the replicate columns of each row using neighboring values. If the data frame ends in null values (the last columns are nulls), it will extrapolate from the last value. If the first value is null, it will loop around and pull from the last replicate to perform the interpolation between the last replicate and the second replicate.

See also

find_next_good_datapoint for details on the interpolation process.

Examples

my_data <- matrix(
   c(
     1, 60, 1, 2, 3, 4, 5,   # No NA values
     1, 90, 9, NA, 4, NA, 2,  # NA Values in row
     1, 120, 3, 6, NA, NA, 9  # Consecutive NA values
    ),
    nrow = 3,
    byrow=TRUE
 )
cleaned_data <- clean_data(my_data, n_trials = 3, n_replicates = 5)
print(my_data)
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,]    1   60    1    2    3    4    5
#> [2,]    1   90    9   NA    4   NA    2
#> [3,]    1  120    3    6   NA   NA    9
print(cleaned_data)
#>      [,1] [,2] [,3] [,4] [,5]  [,6] [,7]
#> [1,]    1   60    1    2  3.0  4.00    5
#> [2,]    1   90    9   11  4.0  6.00    2
#> [3,]    1  120    3    6 10.5 15.75    9