[R] How to match strings in two files and replace strings?

Ana Marija @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com
Tue Mar 31 02:08:44 CEST 2020

I have a file like this: (has 308545 lines)

    head output11.frq
     CHR               SNP   A1   A2          MAF  NCHROBS
       1      1:775852:T:C    T    C       0.1707     3444
       1     1:1120590:A:C    C    A      0.08753     3496
       1     1:1145994:T:C    C    T       0.1765     3496
       1     1:1148494:A:G    A    G       0.1059     3464
       1     1:1201155:C:T    T    C      0.07923     3496

And another file (marker-info) which has the first 24 commented lines
and is comma separated that looks like this (has total of 500593


I want to replace in output11.frq second column with the 5th column in
marker-info that has the matching value in 1st and 2nd column so for
this example the result of the output11.frq would look like this:

    1      rs2980300    T    C       0.1707     3444
    1      rs4245756    T    C      0.07923     3496

I tried doing this in bash but I got empty file:

    vi tst.awk
    NR==FNR { map[$1,$2]=$5; next }
    ($1,$4) in map { $2=map[$1,$4]; print }
    awk -f tst.awk FS=',' marker-info FS='\t' output11.frq  > output11X.frq

Can this be done in R?


More information about the R-help mailing list