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
          Current Approaches to Protein Sequencing
          by seqadmin


          Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
          04-04-2024, 04:25 PM
        • seqadmin
          Strategies for Sequencing Challenging Samples
          by seqadmin


          Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
          03-22-2024, 06:39 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by seqadmin, 04-11-2024, 12:08 PM
        0 responses
        18 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-10-2024, 10:19 PM
        0 responses
        22 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-10-2024, 09:21 AM
        0 responses
        16 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-04-2024, 09:00 AM
        0 responses
        47 views
        0 likes
        Last Post seqadmin  
        Working...
        X