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
          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
        • SEQadmin2
          New Genomics Technologies Take Aim at Long-Standing Limits
          by SEQadmin2


          Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

          We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
          ...
          09-28-2026, 10:25 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by SEQadmin2, 10-22-2026, 11:13 AM
        0 responses
        39 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 10-22-2026, 10:48 AM
        0 responses
        28 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 10-15-2026, 10:52 AM
        0 responses
        41 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 10-14-2026, 05:39 AM
        0 responses
        45 views
        0 reactions
        Last Post SEQadmin2  
        Working...