Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Galgarad
    Junior Member
    • Jul 2012
    • 8

    #1

    kmeans clustering in R

    Hi guys,

    I'm new to R and I'm really close to throwing my cpu in a lake...

    I just can't seem to get the kmeans script to run on my data, using R.

    I really hope you can help me on this.. I have a tab delimited text file with the first column being the nam of the genes, and the two following columns are expression data.

    Ex:

    TPM3 0.014 0.683
    TFF1 4.5 3.567
    ....


    While in R, i do the following:
    > data<-read.table("file path to the data", row.names=1)
    > datam<-as.matrix(data)
    >k<-kmeans(datam, 3)


    and then I have that *&/%/$ error :
    Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
    In addition: Warning message:
    In kmeans(datam, 3) : NAs introduced by coercion


    I've been searching the web for the anwser a lot, and I couldn't find how to fix it. I tried loading a .csv instead of a .txt, but nothing works. From what I have read, it seems that the problem is that there are some blank spaces in my file. But even if I do the
    > datak<-na.omit(datam)
    > k<-kmeans(datak, 3)

    I get the same error..

    Please help me!!!

    Phil
  • Bukowski
    Senior Member
    • Jan 2010
    • 388

    #2
    I don't think it's blank spaces in the data - R would most likely spit a scan error about the lack of elements in the input before you even got to passing it to kmeans.

    I think you most likely have non-numeric data in one of your numeric input columns. Sanity check the input file first.

    See:

    > data
    V2 V3
    gene1 1 2
    gene2 3 4
    gene7 9 0
    gene3 4 5
    gene4 5 6
    > k<-kmeans(data, 3)
    > k
    K-means clustering with 3 clusters of sizes 3, 1, 1


    vs

    > data
    V2 V3
    gene1 1 2
    gene2 3 4
    gene7 9 0
    gene3 4 5
    gene4 5 6
    gene9 F 10
    > k<-kmeans(data, 3)
    Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
    In addition: Warning message:
    In do_one(nmeth) : NAs introduced by coercion
    Last edited by Bukowski; 09-07-2012, 11:46 AM.

    Comment

    • Galgarad
      Junior Member
      • Jul 2012
      • 8

      #3
      You were right.

      I had a 3,9 E + 10 somewhere.

      I thought I checked the file thouroughly, but it seems like I didn't

      Thanks a lot!!!

      Comment

      • jp.
        Senior Member
        • Jul 2013
        • 142

        #4
        hi all
        I got the same error which is "Error in hclustfun(distfun(if (symm) x else t(x))) :
        NA/NaN/Inf in foreign function call (arg 11)".
        I have multiple missing values and I have entered NA. If there few "NA", it goes well and makes heatmap with white (no color) of NA.
        But if there are many NA then only it gives error...
        My commands are:
        > t<- as.matrix(read.table("tmp.txt", sep="\t",header=T, na.strings = "NA", as.is=T,row.names=1))
        > heatmap.2(t, trace="none", ylab="Gene_Name", xlab="Sample_Name", margin=c(7,20), density.info="histogram",na.color=NA, keysize=0.8, densadj=0.025, scale="row", cexRow=1, cexCol=1,dendrogram="both",Rowv=T,Colv=T,key=T,hclustfun=hclust,col = greenred(100))

        Can anybody give me solution ? I want to make heatmap with multiple or numerous NA values.
        Thank you
        jp.

        Comment

        Latest Articles

        Collapse

        • SEQadmin2
          16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
          by SEQadmin2




          NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification, detection...
          Today, 06:46 AM
        • SEQadmin2
          Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
          by SEQadmin2



          Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

          Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
          ...
          10-14-2026, 09:55 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by SEQadmin2, 10-28-2026, 09:57 AM
        0 responses
        22 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 10-28-2026, 09:51 AM
        0 responses
        14 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 10-22-2026, 11:13 AM
        0 responses
        67 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 10-22-2026, 10:48 AM
        0 responses
        47 views
        0 reactions
        Last Post SEQadmin2  
        Working...