Given a data frame of the
IndData format, with a
Year column, imputes any missing data using the latest available year.
This function is used inside
The year of data to extract and impute.
A data frame of indicator data, containing a
This expects a data frame in the
IndData format, i.e. it should at least have a
UnitCode column, and a
as well as other columns that are to be imputed. It also presumes that there are multiple observations for each unit code,
i.e. one per year. It then searches for any missing values in the target year, and replaces them with the equivalent points
from previous years. It will replace using the most recently available point.
A list containing:
IndData format data frame from the specified year (
use_year), with missing data imputed using previous years
.$DataYears: A data frame in the same format as
IndData, where each entry shows which year each data point came from.
Points where there was no missing data will have
use_year, imputed points will have the corresponding year used to impute,
and any points in
.$IndDataImp which are still
NA will be be
.$ImpTable: A data frame where each row is a point that was successfully imputed. This is a filtered and arranged version
.$DataYears that focuses only on the imputed points.
.$NImputed: The number of imputed points.
assemble() Assemble a COIN - this function optionally calls
impute() Impute data using other imputation options (not using panel data).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# artificial example using ASEM data # We only have one year of data so we copy it and "pretend" that they are from different years # First, introduce 3 NAs dat2018 <- ASEMIndData dat2018[2, 12] <- NA dat2018[3, 13] <- NA dat2018[4, 14] <- NA # Now make copy, pretending it is the previous year dat2017 <- ASEMIndData dat2017$Year <- 2017 # This df still has one missing point dat2017[4, 14] <- NA # Finally we have a 2016 data frame where none of the previous points are missing dat2016 <- ASEMIndData dat2016$Year <- 2016 # We can now put them together IndData <- rbind(dat2018, dat2017, dat2016) # And extract the 2018 data, with missing data taken from previous years Imp <- extractYear(2018, IndData, impute_latest = TRUE) # View which points have been imputed and the years of data used Imp$ImpTable
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.