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
          Understanding Genetic Influence on Infectious Disease
          by seqadmin




          During the COVID-19 pandemic, scientists observed that while some individuals experienced severe illness when infected with SARS-CoV-2, others were barely affected. These disparities left researchers and clinicians wondering what causes the wide variations in response to viral infections and what role genetics plays.

          Jean-Laurent Casanova, M.D., Ph.D., Professor at Rockefeller University, is a leading expert in this crossover between genetics and infectious...
          09-09-2024, 10:59 AM
        • seqadmin
          Addressing Off-Target Effects in CRISPR Technologies
          by seqadmin






          The first FDA-approved CRISPR-based therapy marked the transition of therapeutic gene editing from a dream to reality1. CRISPR technologies have streamlined gene editing, and CRISPR screens have become an important approach for identifying genes involved in disease processes2. This technique introduces targeted mutations across numerous genes, enabling large-scale identification of gene functions, interactions, and pathways3. Identifying the full range...
          08-27-2024, 04:44 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by seqadmin, Today, 06:25 AM
        0 responses
        9 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, Yesterday, 01:02 PM
        0 responses
        8 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 09-18-2024, 06:39 AM
        0 responses
        10 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 09-11-2024, 02:44 PM
        0 responses
        13 views
        0 likes
        Last Post seqadmin  
        Working...
        X