This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extracting two matched columns from a file

Hi,

I have two list of miRNA-targets, big one is experimentally validated and another list I extracted myself by correlation analysis. I know how to merge by one column but how I can see how many of my miRNA-tragets are exist in experimentally validated list??

> head(data1)
             miRNA  Gene
    1    hsa-let-7 HMGA2
    2    hsa-let-7  NRAS
    3    hsa-let-7  KRAS
    4    hsa-let-7 IGF1R
    5    hsa-let-7 SOCS4
    6 hsa-let-7a-1 c-MYC
    > head(data2)
            miRNA     Gene
    1 hsa-miR-424  SLC25A2
    2 hsa-miR-20b   APCDD1
    3 hsa-miR-30b SERPINI1
    4 hsa-miR-152  TNFSF14
    5 hsa-miR-20b    EGLN1
    6 hsa-miR-20b ARHGEF10
    > dim(data1)
    [1] 62858     2
    > dim(data2)
    [1] 298   2
    >
r mirna

join. this can be easily googled.

2 answers

Try

mg= intersect(data1$Gene , data2$Gene )

UPDATE:

Look at it like this. Here are two dataframes of the same size:

data1 = data.frame(ID = LETTERS[1:10], Gene = LETTERS[10:1])
data2 = data.frame(ID = LETTERS[8:18], Gene = LETTERS[18:8])
mg1 = intersect( data1$Gene, data2$Gene) 
mg1
> mg1
[1] "J" "I" "H"

And, here are two dataframes of different size:

data3 = data.frame(ID = LETTERS[1:10], Gene = LETTERS[10:1])
data4 = data.frame(ID = LETTERS[8:12], Gene = LETTERS[12:8])
mg2 = intersect( data3$Gene, data4$Gene)
mg2
> mg2
[1] "J" "I" "H"

Thank you

mg= intersect(data1$Gene , data2$Gene )

> View(mg)
Error in View : 'names' attribute [4] must be the same length as the vector [1]
> dim(mg)
NULL
>

how can I write mg file???

What if you just write, mg, in the command line?

And since this is a vector it should be length(mg), not dim(mg)!

Look at it like this. Here are two dataframes of the same size:

data1 = data.frame(ID = LETTERS[1:10], Gene = LETTERS[10:1])
data2 = data.frame(ID = LETTERS[8:18], Gene = LETTERS[18:8])
mg1 = intersect( data1$Gene, data2$Gene) 
mg1
> mg1
[1] "J" "I" "H"

And, here are two dataframes of different size:

data3 = data.frame(ID = LETTERS[1:10], Gene = LETTERS[10:1])
data4 = data.frame(ID = LETTERS[8:12], Gene = LETTERS[12:8])
mg2 = intersect( data3$Gene, data4$Gene)
mg2
> mg2
[1] "J" "I" "H"

Log in to answer this question.