Correlation between different files
1
0
Entering edit mode
8.2 years ago
akang ▴ 110

I have a total of 6 files. File1, File2, File3, File4 & File5 have the same structure except for ID's. I want to

  • sum up the values in all rows like rowSums(file1)
  • Match the Id in File1-File5(Column1) to Id in File6 (Column2) and find the correlation between the sum of rows from File1 and column3 of File6 so that for 5 different files I have 5 different values and write it to a file. This is what i tried but of course it doesnt work. Ill appreciate any help.TIA!

    Geno<-read.table("File1", head=TRUE, row.names=1)
    Pheno<-read.table("File6" )
    rowSums(Geno)
    cor(rowSums(Geno), Pheno$V3)
    
    
    File1
      snp1 snp2 snp3
    Id1 0.1 2.3 3.2
    Id2 0.01 2.2 3.5
    Id3 0.004 0.4 1
    
        File2
        snp1 snp2 snp3
        Id4 0.3 2.0 3.0
        Id5 0.1 2.02 3.05
        Id7 0.04 0.04 0.1
    
        File3
        snp1 snp2 snp3
        Id8 0.3 2.0 3.0
        Id9 0.1 2.02 3.05
        Id11 0.04 0.04 0.1
    
        File4
        snp1 snp2 snp3
        Id12 0.3 2.0 3.0
        Id13 0.1 2.02 3.05
        Id14 0.04 0.04 0.1
    
        File5
        snp1 snp2 snp3
        Id15 0.03 2.1 3.7
        Id16 0.01 2.05 3.01
        Id17 0.04 0.04 0.01
    
        File6 (No header)
        0 Id1 0.03 2.1 3.7
        2 Id2 0.01 2.05 3.01
        2 Id3 0.04 0.04 0.01
        0 Id4 0.03 2.1 3.7
        2 Id5 0.01 2.05 3.01
        2 Id6 0.04 0.04 0.01
        0 Id7 0.03 2.1 3.7
        2 Id8 0.01 2.05 3.01
        2 Id9 0.04 0.04 0.01
        0 Id10 0.03 2.1 3.7
        2 Id11 0.01 2.05 3.01
        2 Id12 0.04 0.04 0.01
        2 Id13 0.01 2.05 3.01
        2 Id14 0.04 0.04 0.01
        0 Id15 0.03 2.1 3.7
        2 Id16 0.01 2.05 3.01
        2 Id17 0.04 0.04 0.01
    
R correlation • 1.7k views
ADD COMMENT
0
Entering edit mode
8.2 years ago
Sam ★ 4.7k

Simply put, you need to make sure both vectors are of the correct dimension (e.g. you need to match the samples before performing cor) You can do the following

cor(rowSums(Geno), Pheno$V3[Pheno$V2%in% row.names(Geno)])
ADD COMMENT
0
Entering edit mode

Thanks @Sam. I was trying to use merge but now i understand better. Thanks aton!

ADD REPLY

Login before adding your answer.

Traffic: 2627 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6