Skip to content
RDocumentation: impute.knn
  • AI Chat
  • Code
  • Report
  • Note that this notebook was automatically generated from an RDocumentation page. It depends on the package and the example code whether this code will run without errors. You may need to edit the code to make things work.

    if(!require('impute')) {
        install.packages('impute')
        library('impute')
    }
    Run cancelled
    data(khanmiss)
    khan.expr <- khanmiss[-1, -(1:2)]
    ##
    ## First example
    ##
    if(exists(".Random.seed")) rm(.Random.seed)
    khan.imputed <- impute.knn(as.matrix(khan.expr))
    ##
    ## khan.imputed$data should now contain the imputed data matrix
    ## khan.imputed$rng.seed should contain the random number seed used
    ## in imputation. In the above invocation, it is the default seed.
    ##
    khan.imputed$rng.seed # should be 362436069
    khan.imputed$rng.state # should be NULL
    ##
    ## Second example
    ##
    set.seed(12345)
    saved.state <- .Random.seed
    khan.imputed <- impute.knn(as.matrix(khan.expr))
    # Assuming all goes well with no guarantees in case of error...
    .Random.seed <- khan.imputed$rng.state
    sum(saved.state - khan.imputed$rng.state) # should be zero!
    save(khan.imputed, file="khanimputation.Rda")