Description Usage Arguments Details Value Author(s) Examples

View source: R/Computing_Functions.R

A function to impute missing values by taking average of adjacent, same-day-of week dates. e.g. If March 5th, Monday, is missing, impute the value by taking average of Mondays in the weeks prior and after.

1 | ```
Compute_DoW_average(data, var_name, bin_past = 0, bin_future = 0)
``` |

`data` |
Name of data frame |

`var_name` |
Name of the variable, of which we are interested in imputing missing values |

`bin_past` |
Number of prior adjoint dates to use for calculating average |

`bin_future` |
Number of post adjoint dates to use for calculating average |

Each element of input variable has to be matched to consecute dates. The function operates under the assumption that the vector is sorted from oldest to the most recent date, and that there is no absent date.

By default the function starts imputing from the oldest to the most recent missing value. This may result in different imputed values from imputing in the reverse order (from recent to the oldest), since the later-imputed missing values may use earlier-imputed values as input for imputation. If you would like to impute from the most recent to the oldest date, reverse the order of the input variable.

By default, the missing values at the start and end of input variable vector, if they do not have enough prior or post values to impute using Compute_DoW_average, will be replaced by the mean of the variable.

Variable, in vector format, with missing values imputed. The non-missing values are same as the original input vector.

Jimin Lauren Yoo

1 2 3 | ```
X=c(1,2,NA,NA,NA,6,7,8,3,0,4,7,7,5,6,0,2,4,1,4,NA,9,0)
data=data.frame("ID" = 1:23, "X" = X)
Compute_DoW_average(data, "X", bin_past=3, bin_future=0)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.