Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #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


    • #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


      • #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

        • seqadmin
          Advancing Precision Medicine for Rare Diseases in Children
          by seqadmin




          Many organizations study rare diseases, but few have a mission as impactful as Rady Children’s Institute for Genomic Medicine (RCIGM). “We are all about changing outcomes for children,” explained Dr. Stephen Kingsmore, President and CEO of the group. The institute’s initial goal was to provide rapid diagnoses for critically ill children and shorten their diagnostic odyssey, a term used to describe the long and arduous process it takes patients to obtain an accurate...
          12-16-2024, 07:57 AM
        • seqadmin
          Recent Advances in Sequencing Technologies
          by seqadmin



          Innovations in next-generation sequencing technologies and techniques are driving more precise and comprehensive exploration of complex biological systems. Current advancements include improved accessibility for long-read sequencing and significant progress in single-cell and 3D genomics. This article explores some of the most impactful developments in the field over the past year.

          Long-Read Sequencing
          Long-read sequencing has seen remarkable advancements,...
          12-02-2024, 01:49 PM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by seqadmin, 12-17-2024, 10:28 AM
        0 responses
        22 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 12-13-2024, 08:24 AM
        0 responses
        42 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 12-12-2024, 07:41 AM
        0 responses
        28 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 12-11-2024, 07:45 AM
        0 responses
        42 views
        0 likes
        Last Post seqadmin  
        Working...
        X