Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8637861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:34:52+00:00 2026-06-12T10:34:52+00:00

I’m new to R, but I’m trying to estimate a missing value in a

  • 0

I’m new to R, but I’m trying to estimate a missing value in a large microarray dataset using impute.knn() from library(impute) using 6 nearest neighbors.

Here’s an example:

seq1 <- seq(1:12)
mat1 <- matrix(seq1, 3)
mat1[2,2] <- "NA"
impute.knn(mat1, k=6)

I get the following error:

Error in knnimp.internal(x, k, imiss, irmiss, p, n, maxp = maxp) : 
NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning message:
In storage.mode(x) <- "double" : NAs introduced by coercion

I’ve also tried the following:

impute.knn(mat1[2,2], k=6)

and I get the following error:

Error in rep(1, p) : invalid 'times' argument

My google-fu has been off today. Any suggestions to why I might be getting this error?

edit: I’ve tried

mat1[2,2] <- NA 

as James suggested, but I get a segmentation fault. Using

replace(mat1, mat1[2,2], NA) 

does not help either. Any other suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:34:53+00:00Added an answer on June 12, 2026 at 10:34 am

    I’m not sure why impute.knn is set up the way it is, but the example within ?impute.knn uses khanmiss which is a data.frame of factors, which when coerced to matrix will be character.

    You are getting a segmentation fault because you are trying to impute with K > ncol(mat1) nearest neighbours. It might be worth reported a bug to the package authors, as this could easily be checked in R and return an error, not a C level error which kills R.

    mat1 <- matrix(as.character(1:12), 3)
    mat1[2,2] <- NA # must not be quoted for it to be a NA value
    # mat1 is a 4 column matrix so
    impute.knn(mat1, 1)
    impute.knn(mat1, 2)
    impute.knn(mat1, 3)
    impute.knn(mat1, 4)
    # Will all work 
    

    note

    despite the strange example, mat1will when it is integer or double as well

    mat1 <- matrix(1:12,3)
    mat1[2,2] <- NA
    impute.knn(mat1,2)
    
    mat1 <- matrix(seq(0,1,12),3)
    mat1[2,2] <- NA
    impute.knn(mat1,2)
    

    take home message

    Don’t try to use impute using more information than you have.

    Perhaps the package authors should take heed of

    fortunes(15)
    

    It really is hard to anticipate just how silly users can be. —Brian D.
    Ripley R-devel (October 2003)

    and build in some error checking so a simple error does not cause a segfault.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.