Take the following data table:
# IMPUTING VALUES set.seed(1337) mydt <- data.table(Year = rep(2000:2005, each = 10), Type = c("A","B"), Value = 30 + rnorm(60) ) naRows <- sample(nrow(mydt),15) mydt[ naRows, Value := NA] setkey(mydt,Year,Type)
How can I impute NS median by year and type? I tried the following
# computed medians computedMedians <- mydt[, .(Median = median(Value, na.rm = TRUE)), keyby = .(Year,Type)]
but when you run the code, you will see that it works if the group does not receive the data completely, and the calculated medians receive recirculation. Is there an easier way? or how can you get a fix for only the last error?
thanks
source share