Replaces NAs in a single column of a data frame with an imputed uninformative
numeric replacement value, so that a principal component analysis can be
applied without discarding data. Optionally adds a new "flag" column which
contains 1 for each row which originally contained NA, otherwise
0.
If not NULL, specifies the name of a new column to be added
to the data frame, with value 0 for non-NA rows, 1 for NA rows. The column
is added regardless of whether there are any NAs in the data.
df <- data.frame(x = c(1, 2, 3), y = c(NA, 5, 6), z = c(NA, NA, 9))
# Eliminate NAs in y, add a flag column, ignore other NAsdf <- TrajsStatsReplaceNAs(df, "y", flagColumn = "y.was.NA")
print(df)