Question: (Closed) how compare rows together?
0
gravatar for star
4.2 years ago by
star230
Netherlands
star230 wrote:

I have  data like as below:
I want to compare each row with rows below and then get number of equal value in each 2 rows.

       V1  V2  V3   V4  V5
    1   3   2   2   3   3
    2   2   2   0   2   3
    3   2   3   2   2   0
    4   0   3   2   1   3
    5   2   2   2   2   3
I wrote the code below, but in out put I face with NA.

    library(data.table)
    data=as.data.frame(read.table("data.csv",header=TRUE))

    findMatch <- function(i,n){
      tmp <- colSums(t(data[-(1:i),]) == unlist(data[i,]))
      tmp <- tmp[tmp > n]
      if(length(tmp) > 0)return(data.table(sample=rownames(data[i],duplicate=names(tmp),match=tmp))
      return(NULL)
    }
    tab <- rbindlist(lapply(1:(nrow(data)-1),findMatch,n=0))
    tab

out put:
     
           sample duplicate match
     1:      1        NA    NA
     2:      1        NA    NA
     3:      1        NA    NA
     4:      1        NA    NA
     
I expect this out put:

           sample duplicate match
     1:      1        2    2
     2:      1        3    1
     3:      1        4    2
     4:      1        5    3

statistics bioconductor R • 1.0k views
ADD COMMENTlink modified 4.2 years ago • written 4.2 years ago by star230
1

Hello star!

We believe that this post does not fit the main topic of this site.

Not sufficiently relevant for bioinformatics, try stackoverflow for example.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

ADD REPLYlink written 4.2 years ago by Michael Dondrup47k

This is not directly related to bioinformatics. You may have better luck at http://stackoverflow.com/

ADD REPLYlink modified 3 months ago by RamRS26k • written 4.2 years ago by Biomonika (Noolean)3.1k
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1082 users visited in the last hour