how to use the result of impute.mean function in R? -
i have dataset of 1302 sample in create mcar nas deleting 5 percent of training part. try impute 5 percent mean of other 95%. don't know how access result produced impute.mean function of hotdeckimputation package.
in package manual guide, says result in form of matrix, can tell me how define matrix record result? according package, matrix should have same size input of function(data).
you can see code below:
navalues = imptrainfolds[sample(nrow(trainfolds), 5),i] imptrainfolds[navalues,i] = na if(imptype == "mean"){ #calculate mean remaining samples ? = impute.mean(data = as.matrix(imptrainfolds[[i]])) }
broadly speaking, if intention replace missing values in data using means, can use code below:
# simulate data n <- 10000 x1 <- rbinom(n,1,prob=.4) x2 <- rnorm(n,0,1) dta <- data.frame(x1, x2) dta$x2[dta$x1 == 1] <- na # replace missing data (i in which(sapply(dta, is.numeric))) { dta[is.na(dta[, i]), i] <- mean(dta[, i], na.rm = true) }
the few things worth considering are:
- this not sophisticated method, packages
amelia ii
offer more comprehensive way of handling missing data - it keep flag data replaced, in code above
dta$x1 == 1
may consider making more explicit adding column
Comments
Post a Comment